﻿using BusinessEntity;
using BusinessEntity.xmglQuerryEntity;
using BusinessRule;
using learun.util;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Nacos.AspNetCore;
using Newtonsoft.Json.Linq;
using ProjectManApi.Extensions;
using System;
using System.Collections.Generic;
using System.Data;
using System.Dynamic;
using System.Linq;
using System.Threading.Tasks;

namespace ProjectManApi.Controllers.xmgl
{
    public class ProJunGongController : MvcControllerBase
    {
        private readonly INacosServerManager _serverManager;
        public ProJunGongController(INacosServerManager serverManager) : base(serverManager)
        {
            _serverManager = serverManager;
        }

        #region 竣工列表（项目名称、建设单位、状态、施工单位）ProJunGongLists.aspx、竣工ProJunGongAdd.aspx、取消竣工

        #region 导出

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> ExportJunGongList(dynamic expjson)
        {

            JObject job = (JObject)expjson;

            List<string> ids = new List<string>();
            List<ColumnModel> cols = new List<ColumnModel>();

            if (null != job["ids"])
                ids = job["ids"].ToObject<string[]>().ToList();

            if (null != job["cols"])
                cols = job["cols"].ToObject<ColumnModel[]>().ToList();

            return File(await CProTZJHRule.GetExportList(ids, cols, BaseEditPower.TableName.竣工, "项目竣工列表"), "application/ms-excel", "竣工管理列表.xls");
        }

        #endregion

        /// <summary>
        /// 竣工列表
        /// </summary>
        /// <param name="xmmc"></param>
        /// <param name="jf"></param>
        /// <param name="yf"></param>
        /// <param name="jgstatus"></param>
        /// <param name="current"></param>
        /// <param name="size"></param>
        /// <param name="sort"></param>
        /// <param name="column"></param>
        /// <returns></returns>
        [HttpGet]
        //[Authorize(Policy = "TestPolicy")]
        //[AllowAnonymous]
        //string formCode,
        public async Task<IActionResult> GetJunGongList(string formCode, string xmmc, string dxmc, string xmfzr, string jf, string yf, string jgstatus, string status, string current = "1", string size = "20", string sort = "desc", string column = "id")
        {
            try
            {
                ProJunGongQuerry querry = new ProJunGongQuerry();
                //基础属性
                querry.size = CommonHelper.ParseInt(size);
                querry.current = CommonHelper.ParseInt(current);
                querry.sort = sort;
                querry.column = column;

                querry.Xmmc = xmmc;
                querry.dxmc = dxmc;
                querry.xmfzr = xmfzr;

                querry.Jf = jf;
                querry.Yf = yf;
                querry.JgStatus = jgstatus;

                querry.status = status;

                (IEnumerable<dynamic>, int) SelectTable = await ProJunGongRule.GetJunGongList(querry, await GetDepId());//GetUserId()


                string strlx = await CProTZJHRule.GetFunGLListBylxEunm(BaseEditPower.JumpModule.竣工验收计划.ToString());
                //如果没关联了验收计划
                if (strlx != "1")
                {
                    List<string> list = new List<string>();
                    foreach (dynamic item in SelectTable.Item1)
                    {
                        string id = item.id;
                        list.Add(id);
                    }

                    List<JavaApi.SPSDataItem> spitems = await JavaApi.GetSPStatusJavaAPI(formCode, GetUserAccount(), list, await GetICApiInfo());
                    foreach (dynamic item in SelectTable.Item1)
                    {
                        string id = item.id;
                        var spstatus = spitems.Where(ii => ii.businessId == id).FirstOrDefault();

                        item.panguData = GetPanGudData(spstatus, item.spstatus);
                    }
                }

                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                return Success(pa);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 合同竣工
        /// </summary>
        /// <param name="htid"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetJGByhtid(string htid)
        {
            try
            {
                var SelectTable = await ProJunGongRule.GetJGByhtid(htid);

                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 单条竣工
        /// </summary>
        /// <param name="jgid"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetJGByid(string jgid)
        {
            try
            {
                var SelectTable = await ProJunGongRule.GetJGByid(jgid);

                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }



        /// <summary>
        /// 插入修改
        /// </summary>
        /// <param name="jgjson"></param>
        /// <returns></returns>
        [HttpPost]
        //[AllowAnonymous]
        public async Task<IActionResult> InsertCProJG(dynamic jgjson)//, string strlx
        {
            string strope = "add";
            CProJG jg = new CProJG();


            //添加附件上传
            FileUploadent filecodes = new FileUploadent();
            try
            {
                JObject job = (JObject)jgjson;

                //获取方法
                strope = jgjson.ope ?? "";
                strope = strope.ToLower();

                //获取实体类 这样复杂类型不用定义实体类
                jg = job["jg"].ToObject<CProJG>();

                //if (null != job["tzxmids"])
                //    tzxmids = job["tzxmids"].ToObject<List<CProManageTZXM>>();

                //接收附件列表
                if (null != job["apiargs"])
                    filecodes = job["apiargs"].ToObject<FileUploadent>();


                if (strope != "add" && strope != "edit" && strope != "approved" && strope != "submit")
                {
                    return Fail("参数ope 不合法");
                }

            }
            catch (Exception ex)
            {
                return Fail("参数转换出错：" + ex.Message);
            }

            try
            {

                string strlsope = strope;
                if (strope == "submit")
                {
                    if (string.IsNullOrEmpty(jg.id))//完成新增
                    {
                        strope = "add";
                    }
                    else
                    {
                        CProJG jhe = await TranstionRule.FindEntityByKey<CProJG>(jg.id);
                        if (null == jhe)
                        {
                            strope = "add";
                        }
                        else
                        {
                            strope = "edit";
                        }
                    }
                    jg.status = BaseEditPower.GetSPEnumValue("待审核");
                }

                if (strope == "add")
                {
                    if (string.IsNullOrEmpty(jg.htid))
                    {
                        return Fail("竣工信息htid不能为空");
                    }
                    if (string.IsNullOrEmpty(jg.jgrq.ToString()))
                    {
                        return Fail("竣工信息竣工日期不能为空");
                    }

                    jg.id = CommonHelper.GetUniqueId().ToString();
                    jg.createuser = GetUserId();
                    jg.createdate = DateTime.Now;
                    jg.jgbm = await JavaApi.BusinessBMJavaAPI(BaseEditPower.listTableName[BaseEditPower.TableName.竣工.ToString()], Newtonsoft.Json.JsonConvert.SerializeObject(jgjson), await GetICApiInfo());
                    //await BusinessRule.Assets.CreateZCDM("XM", "JG");

                    if (strlsope != "submit")
                        jg.status = BaseEditPower.GetSPEnumValue("待提交");

                    CProJG jge = await TranstionRule.FindEntity<CProJG>(new { htid = jg.htid });
                    if (null != jge)
                    {
                        return Fail("该合同id竣工信息已经存在不能新增操作");
                    }

                    //这里先绑定附件
                    await JavaApi.UploadFileJavaAPI(jg.id, filecodes, await GetICApiInfo());

                    bool bsp = true;
                    if (strlsope == "submit")
                    {
                        bsp = false;

                        //CProJG jhe = await TranstionRule.FindEntityByKey<CProJG>(jg.id);
                        //if (null == jhe)
                        //{
                        //    return Fail("根据id未检索到竣工信息");
                        //}

                        var url = BaseEditPower.GetSPDetailUrlS(BaseEditPower.TableName.竣工.ToString(), jg.id);

                        JavaApi.SPLEnt.Auditdescription _description = new JavaApi.SPLEnt.Auditdescription() { businessNo = jg.jgbm, amount = jg.jgrq?.ToString("yyyy-MM-dd"), content = "[项目竣工]" + jg.remark, deptName = GetUserDeptName() };

                        JavaApi.SPLEnt spl = new JavaApi.SPLEnt(BaseEditPower.TableName.竣工.ToString(), jg.id, filecodes.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(jgjson), "http://ic-xmzc/netapi/ProTZJH/UpdateStatus", url.Item1, url.Item2, _description);
                        //bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                        //if (!bsp)
                        string strInstanceId = await JavaApi.startInstanceJavaAPIStr(spl, await GetICApiInfo());
                        jg.spl = strInstanceId;
                        if (strInstanceId.StartsWith("err"))
                        {
                            return Fail("提交失败，启动工作流异常");
                        }
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(jg.id.ToString()))
                    {
                        return Fail("竣工信息id不能为空");
                    }

                    if (!await BaseEditPower.GetEditPower(jg.id, BaseEditPower.TableName.竣工))
                    {
                        return Fail("响应失败:请确认数据权限");
                    }

                    //这里先绑定附件
                    await JavaApi.UploadFileJavaAPI(jg.id, filecodes, await GetICApiInfo());

                    bool bsp = true;
                    if (strlsope == "submit")
                    {
                        bsp = false;

                        CProJG jhe = await TranstionRule.FindEntityByKey<CProJG>(jg.id);
                        if (null == jhe)
                        {
                            return Fail("根据id未检索到竣工信息");
                        }

                        var url = BaseEditPower.GetSPDetailUrlS(BaseEditPower.TableName.竣工.ToString(), jg.id);

                        JavaApi.SPLEnt.Auditdescription _description = new JavaApi.SPLEnt.Auditdescription() { businessNo = jhe.jgbm, amount = jg.jgrq?.ToString("yyyy-MM-dd"), content = "[项目竣工]" + jg.remark, deptName = GetUserDeptName() };

                        JavaApi.SPLEnt spl = new JavaApi.SPLEnt(BaseEditPower.TableName.竣工.ToString(), jg.id, filecodes.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(jgjson), "http://ic-xmzc/netapi/ProTZJH/UpdateStatus", url.Item1, url.Item2, _description);
                        //bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                        //if (!bsp)
                        string strInstanceId = await JavaApi.startInstanceJavaAPIStr(spl, await GetICApiInfo());
                        jg.spl = strInstanceId;
                        if (strInstanceId.StartsWith("err"))
                        {
                            return Fail("提交失败，启动工作流异常");
                        }
                    }
                }



                await BusinessRule.ProJunGongRule.InsertCProJG(jg, strope, GetUserId());

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 插入修改
        /// </summary>
        /// <param name="jgjson"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertCProJGFromNode(dynamic jgjson)
        {
            string strope = "add";
            CProJG jg = new CProJG();


            //添加附件上传
            FileUploadent filecodes = new FileUploadent();
            try
            {
                JObject job = (JObject)jgjson;

                //获取方法
                strope = jgjson.ope ?? "";
                strope = strope.ToLower();

                //获取实体类 这样复杂类型不用定义实体类
                jg = job["jg"].ToObject<CProJG>();

                //if (null != job["tzxmids"])
                //    tzxmids = job["tzxmids"].ToObject<List<CProManageTZXM>>();

                //接收附件列表
                if (null != job["apiargs"])
                    filecodes = job["apiargs"].ToObject<FileUploadent>();


                if (strope != "add" && strope != "edit" && strope != "approved" && strope != "submit")
                {
                    return Fail("参数ope 不合法");
                }

            }
            catch (Exception ex)
            {
                return Fail("参数转换出错：" + ex.Message);
            }

            try
            {

                string strlx = await CProTZJHRule.GetFunGLListBylxEunm(BaseEditPower.JumpModule.竣工验收计划.ToString());

                if (strlx == "1")
                {
                    if (string.IsNullOrEmpty(jg.nodeid))
                    {
                        return Fail("竣工信息nodeid不能为空");
                    }
                }

                //if (string.IsNullOrEmpty(jg.nodeid))
                //{
                //    return Fail("竣工信息nodeid不能为空");
                //}

                if (string.IsNullOrEmpty(jg.htid))
                {
                    return Fail("竣工信息htid不能为空");
                }
                if (string.IsNullOrEmpty(jg.jgrq.ToString()))
                {
                    return Fail("竣工信息竣工日期不能为空");
                }

                jg.id = CommonHelper.GetUniqueId().ToString();
                jg.createuser = GetUserId();
                jg.createdate = DateTime.Now;

                jg.status = BaseEditPower.GetSPEnumValue("通过");

                //这里先绑定附件
                await JavaApi.UploadFileJavaAPI(jg.id, filecodes, await GetICApiInfo());

                //bool bsp = true;
                //if (strlsope == "submit")
                //{
                //    bsp = false;
                //    JavaApi.SPLEnt spl = new JavaApi.SPLEnt(BaseEditPower.TableName.竣工.ToString(), jg.id, filecodes.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(jgjson), "http://ic-xmzc/netapi/ProTZJH/UpdateStatus");
                //    bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                //    if (!bsp)
                //    {
                //        return Fail("提交失败，启动工作流异常");
                //    }
                //}

                await BusinessRule.ProJunGongRule.InsertCProJG(jg, strope, GetUserId());

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        ///// <summary>
        ///// 插入修改
        ///// </summary>
        ///// <param name="jg"></param>
        ///// <returns></returns>
        //[HttpPost]
        //[AllowAnonymous]
        //public async Task<IActionResult> InsertCProJG(CProJG jg, string strlx)
        //{
        //    try
        //    {
        //        string strope = strlx.ToLower();
        //        if (strope != "add" && strope != "edit")
        //        {
        //            return Fail("strlx参数错误");
        //        }

        //        if (strope == "add")
        //        {
        //            if (string.IsNullOrEmpty(jg.htid.ToString()))
        //            {
        //                return Fail("竣工信息htid不能为空");
        //            }
        //            if (string.IsNullOrEmpty(jg.jgrq.ToString()))
        //            {
        //                return Fail("竣工信息竣工日期不能为空");
        //            }

        //            jg.id = CommonHelper.GetUniqueId().ToString();
        //            jg.createuser = GetUserId();
        //            jg.createdate = DateTime.Now;
        //            jg.status = BaseEditPower.GetSPEnumValue("待提交");

        //            CProJG jge = await TranstionRule.FindEntity<CProJG>(new { htid = jg.htid });
        //            if (null != jge)
        //            {
        //                return Fail("该合同id竣工信息已经存在不能新增操作");
        //            }
        //        }
        //        else
        //        {
        //            if (string.IsNullOrEmpty(jg.id.ToString()))
        //            {
        //                return Fail("竣工信息id不能为空");
        //            }

        //            if (!await BaseEditPower.GetEditPower(jg.id, BaseEditPower.TableName.竣工))
        //            {
        //                return Fail("响应失败:请确认数据权限");
        //            }
        //        }

        //        await BusinessRule.ProJunGongRule.InsertCProJG(jg, strope, GetUserId());

        //        return Success("成功");
        //    }
        //    catch (Exception ex)
        //    {
        //        return Fail(ex.Message);
        //    }
        //}

        /// <summary>
        /// 根据根据htid删除多条数据
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteCProJGMulti(Root ids)
        {
            try
            {
                foreach (BaseDeleteMulti idm in ids.ids)
                {
                    if (!await BaseEditPower.GetEditPower(idm.id, BaseEditPower.TableName.竣工))
                    {
                        throw new Exception("请确认数据权限");
                    }
                }

                await BusinessRule.ProJunGongRule.DeleteCProJGMulti(ids);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        #endregion

        #region 结算列表（项目名称、合同甲方、合同编号、状态）ProJieSuanLists.aspx、项目送审ProJieSuanSS.aspx、项目审计ProJieSuanSJ.aspx、项目不审计、删除

        #region 导出

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> ExportJieSuanList(dynamic expjson)
        {

            JObject job = (JObject)expjson;

            List<string> ids = new List<string>();
            List<ColumnModel> cols = new List<ColumnModel>();

            if (null != job["ids"])
                ids = job["ids"].ToObject<string[]>().ToList();

            if (null != job["cols"])
                cols = job["cols"].ToObject<ColumnModel[]>().ToList();

            //return File(await ProJunGongRule.GetExportJieSuanList(ids, cols), "application/ms-excel", "结算管理列表.xls");

            return File(await CProTZJHRule.GetExportList(ids, cols, BaseEditPower.TableName.结算, "项目结算列表"), "application/ms-excel", "结算管理列表.xls");
        }

        #endregion

        [HttpGet]
        //[Authorize(Policy = "TestPolicy")]
        //[AllowAnonymous]
        public async Task<IActionResult> GetJieSuanList(string formCode, string xmid, string xmmc, string dxmc, string jsdw, string ProjectManager, string jf, string htid, string htbh, string status, string jszt, string current = "1", string size = "20", string sort = "desc", string column = "")
        {
            try
            {
                ProJieSuanQuerry querry = new ProJieSuanQuerry();
                //基础属性
                querry.size = CommonHelper.ParseInt(size);
                querry.current = CommonHelper.ParseInt(current);
                querry.sort = sort;
                querry.column = column;


                querry.Jf = jf;
                querry.Xmmc = xmmc;
                querry.Htid = htid;
                querry.Status = status;
                querry.jszt = jszt;

                querry.htbh = htbh;
                querry.dxmc = dxmc;
                querry.xmfzr = ProjectManager;
                querry.xmid = xmid;
                querry.jsdw = jsdw;


                (IEnumerable<dynamic>, int) SelectTable = await ProJunGongRule.GetJieSuanList(querry, await GetDepId());//GetUserId()

                List<string> list = new List<string>();
                foreach (dynamic item in SelectTable.Item1)
                {
                    string id = item.id;
                    list.Add(id);
                }

                List<JavaApi.SPSDataItem> spitems = await JavaApi.GetSPStatusJavaAPI(formCode, GetUserAccount(), list, await GetICApiInfo());
                foreach (dynamic item in SelectTable.Item1)
                {
                    string id = item.id;
                    var spstatus = spitems.Where(ii => ii.businessId == id).FirstOrDefault();

                    item.panguData = GetPanGudData(spstatus, item.spstatus);
                }

                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                return Success(pa);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 根据合同id 查询审计信息
        /// </summary>
        /// <param name="htid"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetJSByhtid(string htid)
        {
            try
            {
                var SelectTable = await ProJunGongRule.GetJSByhtid(htid);

                if (null != SelectTable)
                {

                    SelectTable.fzrs = await ProHeTongRule.GetHTFuZeRen(htid);

                    var list = await ProJunGongRule.GetJSfileTableByhtid(htid);
                    var lists = list?.ToList() ?? new List<cprojsfile>();
                    var listsjson = new List<cprojsfileJson>();
                    for (int i = 0; i < lists.Count; i++)
                    {
                        cprojsfile it = lists[i];
                        cprojsfileJson jsjson = new cprojsfileJson()
                        {
                            id = it.id,
                            jsid = it.jsid,
                            file = it?.file?.ToList<string>() ?? new List<string>(),//it.file,
                            formCode = it.formCode,
                            title = it.title,
                            filenum = it.filenum,
                            indexs = it.indexs,
                            options = it?.options?.ToList<string>() ?? new List<string>()
                        };

                        listsjson.Add(jsjson);

                    }

                    SelectTable.fileinfo = listsjson;

                    SelectTable.businessIds = await ProJunGongRule.GetXMJSID(htid);
                }

                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 根据审计主键id查询审计信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetJSByid(string id)
        {
            try
            {
                var SelectTable = await ProJunGongRule.GetJSByid(id);

                if (null != SelectTable)
                {
                    string strhtid = SelectTable.htid;
                    SelectTable.fzrs = await ProHeTongRule.GetHTFuZeRen(strhtid);

                    var list = await ProJunGongRule.GetJSfileTableByid(id);

                    var lists = list?.ToList() ?? new List<cprojsfile>();
                    var listsjson = new List<cprojsfileJson>();
                    for (int i = 0; i < lists.Count; i++)
                    {
                        cprojsfile it = lists[i];
                        cprojsfileJson jsjson = new cprojsfileJson()
                        {
                            id = it.id,
                            jsid = it.jsid,
                            file = it?.file?.ToList<string>() ?? new List<string>(),

                            formCode = it.formCode,
                            title = it.title,
                            filenum = it.filenum,
                            indexs = it.indexs,
                            options = it?.options?.ToList<string>() ?? new List<string>()
                        };

                        listsjson.Add(jsjson);

                    }

                    SelectTable.fileinfo = listsjson;

                    SelectTable.businessIds = await ProJunGongRule.GetXMJSID(strhtid);
                }

                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 新增修改项目送审数据
        /// </summary>
        /// <param name="js"></param>
        /// <param name="strlx"></param>
        /// <returns></returns>
        [HttpPost]
        //[AllowAnonymous]
        public async Task<IActionResult> InsertCProJSSS(CProJSCRUD jsjson)//dynamic jsjson string strlx = "xxx"
        {
            string strope = "add";
            CProJS js = new CProJS();
            List<cprojsfileJson> fileinfo = new List<cprojsfileJson>();
            //添加附件上传
            FileUploadent filecodes = new FileUploadent();
            try
            {
                //JObject job = (JObject)jsjson;

                //获取方法
                strope = jsjson.ope ?? "";
                strope = strope.ToLower();

                //获取实体类 这样复杂类型不用定义实体类
                //js = job["js"].ToObject<CProJS>();
                js = jsjson?.js ?? new CProJS();

                //fileinfo = job["fileinfo"].ToObject<List<cprojsfile>>();
                fileinfo = jsjson?.fileinfo ?? new List<cprojsfileJson>();

                //接收附件列表
                //if (null != job["apiargs"])
                //    filecodes = job["apiargs"].ToObject<FileUploadent>();

                if (null != jsjson.apiargs)
                    filecodes = jsjson.apiargs;


                if (strope != "add" && strope != "edit" && strope != "approved" && strope != "submit")
                {
                    return Fail("参数ope 不合法");
                }

            }
            catch (Exception ex)
            {
                return Fail("参数转换出错：" + ex.Message);
            }

            try
            {
                string strlsope = strope;
                if (strope == "submit")
                {
                    if (string.IsNullOrEmpty(js.id))//完成新增
                    {
                        strope = "add";
                    }
                    else
                    {
                        CProJS jhe = await TranstionRule.FindEntityByKey<CProJS>(js.id);
                        if (null == jhe)
                        {
                            strope = "add";
                        }
                        else
                        {
                            strope = "edit";
                        }
                    }
                    js.status = BaseEditPower.GetSPEnumValue("待审核");
                }

                if (strope == "add")
                {
                    if (string.IsNullOrEmpty(js.htid))
                    {
                        return Fail("送审信息htid不能为空");
                    }
                    //if (string.IsNullOrEmpty(js.sjdw))
                    //{
                    //    return Fail("送审信息审计单位不能为空");
                    //}
                    if (null == js.ssrq || string.IsNullOrEmpty(js.ssrq.ToString()))
                    {
                        return Fail("送审信息送审日期不能为空");
                    }
                    if (null == js.ssje || string.IsNullOrEmpty(js.ssje.ToString()))
                    {
                        return Fail("送审信息送审金额不能为空");
                    }

                    js.id = CommonHelper.GetUniqueId().ToString();
                    js.jszt = "1";// BaseEditPower.JSStatus.项目送审.ToString();
                    js.createuser = GetUserName();
                    js.createdate = DateTime.Now;
                    js.jsbm = await JavaApi.BusinessBMJavaAPI(BaseEditPower.listTableName[BaseEditPower.TableName.结算.ToString()], Newtonsoft.Json.JsonConvert.SerializeObject(jsjson), await GetICApiInfo());



                    if (strlsope != "submit")
                        js.status = BaseEditPower.GetSPEnumValue("待提交");

                    //这里先绑定附件
                    await JavaApi.UploadFileJavaAPI(js.id, filecodes, await GetICApiInfo());

                    bool bsp = true;
                    if (strlsope == "submit")
                    {
                        bsp = false;

                        //CProJS jhe = await TranstionRule.FindEntityByKey<CProJS>(js.id);
                        //if (null == jhe)
                        //{
                        //    return Fail("根据id未检索到结算信息");
                        //}


                        var url = BaseEditPower.GetSPDetailUrlS(BaseEditPower.TableName.结算.ToString(), js.id);

                        JavaApi.SPLEnt.Auditdescription _description = new JavaApi.SPLEnt.Auditdescription() { businessNo = js.jsbm, amount = js.ssje?.ToString(), content = "[项目结算]" + js.sssm, deptName = GetUserDeptName() };

                        JavaApi.SPLEnt spl = new JavaApi.SPLEnt(BaseEditPower.TableName.结算.ToString(), js.id, filecodes.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(jsjson), "http://ic-xmzc/netapi/ProTZJH/UpdateStatus", url.Item1, url.Item2, _description);
                        //bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                        //if (!bsp)
                        string strInstanceId = await JavaApi.startInstanceJavaAPIStr(spl, await GetICApiInfo());
                        js.spl = strInstanceId;
                        if (strInstanceId.StartsWith("err"))
                        {
                            return Fail("提交失败，启动工作流异常");
                        }
                    }

                    await BusinessRule.ProJunGongRule.InsertCProJSSS(js, fileinfo, strope, GetUserId());
                }
                else if (strope == "edit")
                {
                    if (string.IsNullOrEmpty(js.id.ToString()))
                    {
                        return Fail("送审信息id不能为空");
                    }

                    if (!await BaseEditPower.GetEditPower(js.id, BaseEditPower.TableName.结算))
                    {
                        return Fail("响应失败:请确认数据权限");
                    }

                    //这里先绑定附件
                    await JavaApi.UploadFileJavaAPI(js.id, filecodes, await GetICApiInfo());

                    bool bsp = true;
                    if (strlsope == "submit")
                    {
                        bsp = false;

                        CProJS jhe = await TranstionRule.FindEntityByKey<CProJS>(js.id);
                        if (null == jhe)
                        {
                            return Fail("根据id未检索到结算信息");
                        }


                        var url = BaseEditPower.GetSPDetailUrlS(BaseEditPower.TableName.结算.ToString(), js.id);

                        JavaApi.SPLEnt.Auditdescription _description = new JavaApi.SPLEnt.Auditdescription() { businessNo = jhe.jsbm, amount = js.ssje?.ToString(), content = "[项目结算]" + js.sssm, deptName = GetUserDeptName() };

                        JavaApi.SPLEnt spl = new JavaApi.SPLEnt(BaseEditPower.TableName.结算.ToString(), js.id, filecodes.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(jsjson), "http://ic-xmzc/netapi/ProTZJH/UpdateStatus", url.Item1, url.Item2, _description);
                        //bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                        //if (!bsp)
                        string strInstanceId = await JavaApi.startInstanceJavaAPIStr(spl, await GetICApiInfo());
                        js.spl = strInstanceId;
                        if (strInstanceId.StartsWith("err"))
                        {
                            return Fail("提交失败，启动工作流异常");
                        }
                    }

                    await BusinessRule.ProJunGongRule.InsertCProJSSS(js, fileinfo, strope, GetUserId());
                }



                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 插入修改审计数据
        /// </summary>
        /// <param name="js"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertCProJSSJ(dynamic jsjson)
        {
            string strope = "add";
            CProJS js = new CProJS();

            //添加附件上传
            FileUploadent filecodes = new FileUploadent();
            try
            {
                JObject job = (JObject)jsjson;

                //获取方法
                strope = jsjson.ope ?? "";
                strope = strope.ToLower();

                //获取实体类 这样复杂类型不用定义实体类
                js = job["js"].ToObject<CProJS>();

                //if (null != job["tzxmids"])
                //    tzxmids = job["tzxmids"].ToObject<List<CProManageTZXM>>();

                //接收附件列表
                if (null != job["apiargs"])
                    filecodes = job["apiargs"].ToObject<FileUploadent>();


                if (strope != "sj")//&& strope != "edit" && strope != "approved"
                {
                    return Fail("参数ope 不合法");
                }

            }
            catch (Exception ex)
            {
                return Fail("参数转换出错：" + ex.Message);
            }


            try
            {
                if (string.IsNullOrEmpty(js.id.ToString()))
                {
                    return Fail("审计信息id不能为空");
                }
                if (string.IsNullOrEmpty(js.sdje.ToString()) || js.sdje == 0)
                {
                    return Fail("审计信息审定金额不能为空");
                }
                if (string.IsNullOrEmpty(js.sdrq.ToString()))
                {
                    return Fail("审计信息审定日期不能为空");
                }

                CProJS jse = await TranstionRule.FindEntityByKey<CProJS>(js.id);
                if (null == jse || jse.status != "2")
                {
                    return Fail("请确认数据状态");
                }

                //直接给赋个值
                js.htid = jse.htid;

                //已审计
                js.jszt = "2";

                //这里先绑定附件
                await JavaApi.UploadFileJavaAPI(js.id, filecodes, await GetICApiInfo());

                await BusinessRule.ProJunGongRule.InsertCProJSSJ(js, GetUserId());

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 不需审计
        /// </summary>
        /// <param name="htids"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertCProJSBSJ(List<string> htids)
        {
            try
            {
                for (int i = 0; i < htids.Count; i++)
                {
                    if (!string.IsNullOrEmpty(htids[i]))
                    {
                        //CProJS js = await TranstionRule.FindEntity<CProJS>(new { htid = htids[i] });
                        //if (null != js)
                        //{
                        //    throw new Exception("请选择送审状态为未送审的数据");
                        //}
                    }
                }


                List<CProJS> list = new List<CProJS>();
                for (int i = 0; i < htids.Count; i++)
                {
                    CProJS js = new CProJS();

                    js.id = CommonHelper.GetUniqueId().ToString();
                    js.htid = htids[i];
                    js.jszt = "3";//不审计
                    js.status = "2";
                    js.createuser = GetUserName();
                    js.createdate = DateTime.Now;

                    list.Add(js);
                }



                await BusinessRule.ProJunGongRule.InsertCProJSBSJ(list, GetUserId());

                return Success("成功");
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 需要审计
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertCProJSXYSJ(List<string> htids)
        {
            try
            {
                for (int i = 0; i < htids.Count; i++)
                {
                    if (!string.IsNullOrEmpty(htids[i]))
                    {
                        CProJS js = await TranstionRule.FindEntity<CProJS>(new { htid = htids[i] });
                        if (null != js && js.jszt != "3")
                        {
                            throw new Exception("请选择无需送审的数据进行操作");
                        }
                    }
                }

                await BusinessRule.ProJunGongRule.DeleteCProJSMulti2(htids);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 根据根据htid删除多条结算数据
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteCProJSMulti(Root ids)
        {
            try
            {
                foreach (BaseDeleteMulti idm in ids.ids)
                {
                    if (!await BaseEditPower.GetEditPowerSJ(idm.id, BaseEditPower.TableName.结算))
                    {
                        throw new Exception("请确认数据权限");
                    }
                }

                await BusinessRule.ProJunGongRule.DeleteCProJSMulti(ids);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        #endregion

        #region 进度日志

        #region 导出

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> ExportHTLogList(dynamic expjson)
        {

            JObject job = (JObject)expjson;

            List<string> ids = new List<string>();
            List<ColumnModel> cols = new List<ColumnModel>();

            if (null != job["ids"])
                ids = job["ids"].ToObject<string[]>().ToList();

            if (null != job["cols"])
                cols = job["cols"].ToObject<ColumnModel[]>().ToList();

            return File(await CProTZJHRule.GetExportList(ids, cols, BaseEditPower.TableName.日志, "现场管理列表"), "application/ms-excel", "现场管理列表.xls");
        }

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> ExportSafeLogList(dynamic expjson)
        {

            JObject job = (JObject)expjson;

            List<string> ids = new List<string>();
            List<ColumnModel> cols = new List<ColumnModel>();

            if (null != job["ids"])
                ids = job["ids"].ToObject<string[]>().ToList();

            if (null != job["cols"])
                cols = job["cols"].ToObject<ColumnModel[]>().ToList();

            return File(await CProTZJHRule.GetExportList(ids, cols, BaseEditPower.TableName.日志safe, "安全日志列表"), "application/ms-excel", "安全日志列表.xls");
        }

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> ExportReportLogList(dynamic expjson)
        {

            JObject job = (JObject)expjson;

            List<string> ids = new List<string>();
            List<ColumnModel> cols = new List<ColumnModel>();

            if (null != job["ids"])
                ids = job["ids"].ToObject<string[]>().ToList();

            if (null != job["cols"])
                cols = job["cols"].ToObject<ColumnModel[]>().ToList();

            return File(await CProTZJHRule.GetExportList(ids, cols, BaseEditPower.TableName.日志report, "周月报列表"), "application/ms-excel", "周月报列表.xls");
        }

        #endregion

        /// <summary>
        /// 项目过程节点
        /// </summary>
        /// <param name="xmmc"></param>
        /// <param name="xmfl"></param>
        /// <param name="jsdw"></param>
        /// <param name="sftb"></param>
        /// <param name="year"></param>
        /// <param name="status"></param>
        /// <param name="current"></param>
        /// <param name="size"></param>
        /// <param name="sort"></param>
        /// <param name="column"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetXMLogsIndexList(string xmmc, string xmfl, string jsdw, string sftb, string year, string status, string current = "1", string size = "20", string sort = "desc", string column = "id")
        {
            try
            {
                CProManageQQQuerry querry = new CProManageQQQuerry();
                //基础属性
                querry.size = CommonHelper.ParseInt(size);
                querry.current = CommonHelper.ParseInt(current);
                querry.sort = sort;
                querry.column = column;


                querry.Jsdw = jsdw;
                querry.Xmmc = xmmc;
                querry.Xmfl = xmfl;
                querry.sftb = sftb;

                querry.year = year;
                querry.status = status;

                //默认已审核
                if (string.IsNullOrEmpty(status))
                {
                    querry.status = "checked";
                }

                (IEnumerable<dynamic>, int) SelectTable = await ProJunGongRule.GetXMLogsIndexList(querry, await GetDepId());



                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                return Success(pa);
            }
            catch (Exception ex)
            {
                return Fail("响应失败" + ex);
            }
        }

        //周报列表
        [HttpGet]
        public async Task<IActionResult> GetReportLogIndexList(string xmmc, string xmfl, string jsdw, string reporter, string yearRange, string rtype, string status, string zgzt, string current = "1", string size = "20", string sort = "desc", string column = "id")
        {
            try
            {
                dynamic dye = new ExpandoObject();
                dye.xmmc = xmmc;
                dye.reporter = reporter;//汇报人
                dye.yearRange = yearRange;
                dye.rtype = rtype;
                //整改状态
                dye.zgzt = zgzt;
                dye.jsdw = jsdw;

                dye.current = current;
                dye.size = size;
                dye.sort = sort;
                dye.column = column;


                (IEnumerable<dynamic>, int) SelectTable = await ProJunGongRule.GetLogsIndexList(dye, "report", await GetDepId());



                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                return Success(pa);
            }
            catch (Exception ex)
            {
                return Fail("响应失败" + ex);
            }
        }

        //安全列表
        [HttpGet]
        public async Task<IActionResult> GetSafeLogIndexList(string xmmc, string xmfl, string jsdw, string reporter, string yearRange, string rtype, string status, string zgzt, string current = "1", string size = "20", string sort = "desc", string column = "id")
        {
            try
            {
                dynamic dye = new ExpandoObject();
                dye.xmmc = xmmc;
                dye.reporter = reporter;//汇报人
                dye.yearRange = yearRange;
                dye.rtype = rtype;

                dye.jsdw = jsdw;

                //整改状态
                dye.zgzt = zgzt;

                dye.current = current;
                dye.size = size;
                dye.sort = sort;
                dye.column = column;


                (IEnumerable<dynamic>, int) SelectTable = await ProJunGongRule.GetLogsIndexList(dye, "safe", await GetDepId());



                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                return Success(pa);
            }
            catch (Exception ex)
            {
                return Fail("响应失败" + ex);
            }
        }

        /// <summary>
        /// 合同日志模板列表
        /// </summary>
        /// <param name="strlx"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHTLogMBList(string strlx = "all")
        {
            try
            {

                var SelectTable = await ProJunGongRule.GetHTLogMBList(strlx);

                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 单条合同日志模板
        /// </summary>
        /// <param name="mbid"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHTLogMBByid(string mbid)
        {
            try
            {
                var SelectTable = await ProJunGongRule.GetHTLogMBByid(mbid);

                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }


        /// <summary>
        /// 修改合同日志
        /// </summary>
        /// <param name="logmb"></param>
        /// <param name="strlx"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertHTLogMB(dynamic logmbjson)//CProConLogMB logmb, string strlx = "xxx"
        {
            string strope = "add";
            CProConLogMB logmb = new CProConLogMB();
            //List<CProManageTZXM> tzxmids = new List<CProManageTZXM>();

            //添加附件上传
            FileUploadent filecodes = new FileUploadent();
            try
            {
                JObject job = (JObject)logmbjson;

                //获取方法
                strope = logmbjson.ope ?? "";
                strope = strope.ToLower();

                //获取实体类 这样复杂类型不用定义实体类
                logmb = job["log"].ToObject<CProConLogMB>();


                //接收附件列表
                if (null != job["apiargs"])
                    filecodes = job["apiargs"].ToObject<FileUploadent>();

                if (strope != "add" && strope != "edit" && strope != "submit")
                {
                    return Fail("参数ope 不合法");
                }
            }
            catch (Exception ex)
            {
                return Fail("参数转换出错：" + ex.Message);
            }


            try
            {
                //string strope = strlx.ToLower();
                //if (strope != "add" && strope != "edit")
                //{
                //    return Fail("strlx参数错误");
                //}

                if (strope == "add")
                {
                    //if (string.IsNullOrEmpty(logmb.htid))
                    //{
                    //    return Fail("变更关联的合同id不能为空");
                    //}

                    //重新赋值一个新id
                    logmb.id = CommonHelper.GetUniqueId().ToString();
                    logmb.createuser = GetUserId();

                    logmb.status = "2";// BaseEditPower.GetSPEnumValue("待提交");


                    //新增投资计划
                    await ProJunGongRule.InsertHTLogMB(logmb, "add");


                }
                else if (strope == "edit")
                {
                    if (string.IsNullOrEmpty(logmb.id))
                    {
                        return Fail("需要修改的日志模板id不能为空");
                    }
                    //if (string.IsNullOrEmpty(logmb.htid))
                    //{
                    //    return Fail("变更关联的合同id不能为空");
                    //}


                    //新增投资计划
                    await ProJunGongRule.InsertHTLogMB(logmb, "edit");
                }


                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail("响应失败:" + ex.Message);
            }
        }

        /// <summary>
        /// 删除合同日志
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteHTLogMBMulti(Root ids)//
        {
            try
            {
                foreach (BaseDeleteMulti idm in ids.ids)
                {
                    if (string.IsNullOrEmpty(idm.id))
                    {
                        return Fail("需要删除的变更编号不能为空");
                    }

                    //if (!await BaseEditPower.GetEditPower(idm.id, BaseEditPower.TableName.合同变更))
                    //{
                    //    //throw new Exception("请确认数据权限");
                    //    return Fail("响应失败:请确认数据权限");
                    //}
                }
            }
            catch (Exception ex)
            {
                return Fail("出错：" + ex.Message);
            }


            try
            {
                //新增投资计划
                if (await ProJunGongRule.DeleteHTLogMB(ids))
                {
                    return Success("成功");
                }
                else
                {
                    return Fail("影响行数为0");
                }

            }
            catch (Exception ex)
            {
                return Fail("响应失败:" + ex.Message);
            }
        }

        /// <summary>
        /// 现场的单位信息
        /// </summary>
        /// <param name="xmid"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetXMCompById(string xmid)
        {
            try
            {
                var SelectTable = await CProManageRule.GetXMByID2(xmid);
                return Success(SelectTable);
            }
            catch (Exception)
            {
                return Fail("响应失败");
            }
        }

        /// <summary>
        /// 合同日志列表(report 周报，月报)
        /// </summary>
        /// <param name="htid"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHTReportLogListByxmid(string xmid, string reptype)
        {
            try
            {
                var SelectTable = await ProJunGongRule.GetHTLogListByxmid(xmid, "report", reptype);

                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 合同日志列表(安全 safe)
        /// </summary>
        /// <param name="xmid"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHTSafeLogListByxmid(string xmid)//string reptype
        {
            try
            {
                var SelectTable = await ProJunGongRule.GetHTLogListByxmid(xmid, "safe", "");


                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 合同日志列表
        /// </summary>
        /// <param name="xmid"></param>
        /// <param name="strlx"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHTLogListByxmid(string xmid, string strlx, string reptype)
        {
            try
            {
                var SelectTable = await ProJunGongRule.GetHTLogListByxmid(xmid, strlx, reptype);

                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }


        /// <summary>
        /// 单条合同日志
        /// </summary>
        /// <param name="logid"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHTLogByid(string logid)
        {
            try
            {
                var SelectTable = await ProJunGongRule.GetHTLogByid(logid);

                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 修改合同日志
        /// </summary>
        /// <param name="logjson"></param>
        /// <param name="strlx"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertHTLog(dynamic logjson)//, string strlx = "xxx"
        {

            string strope = "add";
            CProConLog log = new CProConLog();


            //添加附件上传
            FileUploadent filecodes = new FileUploadent();
            try
            {
                JObject job = (JObject)logjson;

                //获取方法
                strope = logjson.ope ?? "";
                strope = strope.ToLower();

                //获取实体类 这样复杂类型不用定义实体类
                log = job["log"].ToObject<CProConLog>();


                //接收附件列表
                if (null != job["apiargs"])
                    filecodes = job["apiargs"].ToObject<FileUploadent>();


                if (strope != "add" && strope != "edit" && strope != "approved" && strope != "submit")
                {
                    return Fail("参数ope 不合法");
                }

            }
            catch (Exception ex)
            {
                return Fail("参数转换出错：" + ex.Message);
            }
            try
            {
                //string strlsope = strope;
                //if (strope == "submit")
                //{
                //    if (string.IsNullOrEmpty(log.id))//完成新增
                //    {
                //        strope = "add";
                //    }
                //    else
                //    {
                //        CProConLog jhe = await TranstionRule.FindEntityByKey<CProConLog>(log.id);
                //        if (null == jhe)
                //        {
                //            strope = "add";
                //        }
                //        else
                //        {
                //            strope = "edit";
                //        }
                //    }
                //    log.status = BaseEditPower.GetSPEnumValue("待审核");
                //}

                if (strope == "add")
                {
                    if (string.IsNullOrEmpty(log.htid))
                    {
                        return Fail("日志关联的项目id不能为空");
                    }

                    if (string.IsNullOrEmpty(log.lx))
                    {
                        return Fail("日志关联的lx不能为空");
                    }

                    log.rzbm = await JavaApi.BusinessBMJavaAPI(BaseEditPower.listTableName[BaseEditPower.TableName.日志.ToString()], Newtonsoft.Json.JsonConvert.SerializeObject(logjson), await GetICApiInfo());
                    //await BusinessRule.Assets.CreateZCDM("XM", "LOG");
                    //log.tbr = GetUserName();
                    //log.tbrq = DateTime.Now;
                    //重新赋值一个新id
                    log.id = CommonHelper.GetUniqueId().ToString();
                    log.createuser = GetUserId();


                    log.status = BaseEditPower.GetSPEnumValue("通过");

                    //if (strlsope != "submit")
                    //    log.status = BaseEditPower.GetSPEnumValue("待提交");


                    //这里先绑定附件
                    await JavaApi.UploadFileJavaAPI(log.id, filecodes, await GetICApiInfo());

                    //bool bsp = true;
                    //if (strlsope == "submit")
                    //{
                    //    bsp = false;
                    //    JavaApi.SPLEnt spl = new JavaApi.SPLEnt(BaseEditPower.TableName.日志.ToString(), log.id, filecodes.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(logjson), "http://ic-xmzc/netapi/ProTZJH/UpdateStatus");
                    //    bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                    //    if (!bsp)
                    //    {
                    //        return Fail("提交失败，启动工作流异常");
                    //    }
                    //}
                    //新增投资计划
                    await ProJunGongRule.InsertHTLog(log, "add");


                }
                else if (strope == "edit")
                {
                    if (string.IsNullOrEmpty(log.id))
                    {
                        return Fail("需要修改的日志id不能为空");
                    }
                    //if (string.IsNullOrEmpty(log.htid))
                    //{
                    //    return Fail("日志关联的合同id不能为空");
                    //}


                    log.status = BaseEditPower.GetSPEnumValue("通过");

                    //这里先绑定附件
                    await JavaApi.UploadFileJavaAPI(log.id, filecodes, await GetICApiInfo());


                    //bool bsp = true;
                    //if (strlsope == "submit")
                    //{
                    //    bsp = false;
                    //    JavaApi.SPLEnt spl = new JavaApi.SPLEnt(BaseEditPower.TableName.日志.ToString(), log.id, filecodes.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(logjson), "http://ic-xmzc/netapi/ProTZJH/UpdateStatus");
                    //    bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                    //    if (!bsp)
                    //    {
                    //        return Fail("提交失败，启动工作流异常");
                    //    }
                    //}
                    //新增投资计划
                    await ProJunGongRule.InsertHTLog(log, "edit");
                }


                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail("响应失败:" + ex.Message);
            }
        }

        ///// <summary>
        ///// 修改合同日志
        ///// </summary>
        ///// <param name="logjson"></param>
        ///// <param name="strlx"></param>
        ///// <returns></returns>
        //[HttpPost]
        //[AllowAnonymous]
        //public async Task<IActionResult> InsertHTLog(dynamic logjson)//, string strlx = "xxx"
        //{

        //    string strope = "add";
        //    CProConLog log = new CProConLog();


        //    //添加附件上传
        //    FileUploadent filecodes = new FileUploadent();
        //    try
        //    {
        //        JObject job = (JObject)logjson;

        //        //获取方法
        //        strope = logjson.ope ?? "";
        //        strope = strope.ToLower();

        //        //获取实体类 这样复杂类型不用定义实体类
        //        log = job["log"].ToObject<CProConLog>();


        //        //接收附件列表
        //        if (null != job["apiargs"])
        //            filecodes = job["apiargs"].ToObject<FileUploadent>();


        //        if (strope != "add" && strope != "edit" && strope != "approved" && strope != "submit")
        //        {
        //            return Fail("参数ope 不合法");
        //        }

        //    }
        //    catch (Exception ex)
        //    {
        //        return Fail("参数转换出错：" + ex.Message);
        //    }
        //    try
        //    {
        //        string strlsope = strope;
        //        if (strope == "submit")
        //        {
        //            if (string.IsNullOrEmpty(log.id))//完成新增
        //            {
        //                strope = "add";
        //            }
        //            else
        //            {
        //                CProConLog jhe = await TranstionRule.FindEntityByKey<CProConLog>(log.id);
        //                if (null == jhe)
        //                {
        //                    strope = "add";
        //                }
        //                else
        //                {
        //                    strope = "edit";
        //                }
        //            }
        //            log.status = BaseEditPower.GetSPEnumValue("待审核");
        //        }

        //        if (strope == "add")
        //        {
        //            if (string.IsNullOrEmpty(log.htid))
        //            {
        //                return Fail("日志关联的合同id不能为空");
        //            }

        //            log.tbr = GetUserId();
        //            log.tbrq = DateTime.Now;
        //            //重新赋值一个新id
        //            log.id = CommonHelper.GetUniqueId().ToString();
        //            log.createuser = GetUserId();

        //            if (strlsope != "submit")
        //                log.status = BaseEditPower.GetSPEnumValue("待提交");


        //            //这里先绑定附件
        //            await JavaApi.UploadFileJavaAPI(log.id, filecodes, await GetICApiInfo());
        //            bool bsp = true;
        //            if (strlsope == "submit")
        //            {
        //                bsp = false;
        //                JavaApi.SPLEnt spl = new JavaApi.SPLEnt(BaseEditPower.TableName.日志.ToString(), log.id, filecodes.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(logjson), "http://ic-xmzc/netapi/ProTZJH/UpdateStatus");
        //                bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
        //                if (!bsp)
        //                {
        //                    return Fail("提交失败，启动工作流异常");
        //                }
        //            }
        //            //新增投资计划
        //            await ProJunGongRule.InsertHTLog(log, "add");


        //        }
        //        else if (strope == "edit")
        //        {
        //            if (string.IsNullOrEmpty(log.id))
        //            {
        //                return Fail("需要修改的日志id不能为空");
        //            }
        //            //if (string.IsNullOrEmpty(log.htid))
        //            //{
        //            //    return Fail("日志关联的合同id不能为空");
        //            //}

        //            //这里先绑定附件
        //            await JavaApi.UploadFileJavaAPI(log.id, filecodes, await GetICApiInfo());
        //            bool bsp = true;
        //            if (strlsope == "submit")
        //            {
        //                bsp = false;
        //                JavaApi.SPLEnt spl = new JavaApi.SPLEnt(BaseEditPower.TableName.日志.ToString(), log.id, filecodes.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(logjson), "http://ic-xmzc/netapi/ProTZJH/UpdateStatus");
        //                bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
        //                if (!bsp)
        //                {
        //                    return Fail("提交失败，启动工作流异常");
        //                }
        //            }
        //            //新增投资计划
        //            await ProJunGongRule.InsertHTLog(log, "edit");
        //        }


        //        return Success("成功");
        //    }
        //    catch (Exception ex)
        //    {
        //        return Fail("响应失败:" + ex.Message);
        //    }
        //}

        ///// <summary>
        ///// 修改合同日志
        ///// </summary>
        ///// <param name="log"></param>
        ///// <param name="strlx"></param>
        ///// <returns></returns>
        //[HttpPost]
        //[AllowAnonymous]
        //public async Task<IActionResult> InsertHTLog(CProConLog log, string strlx = "xxx")//
        //{
        //    try
        //    {
        //        string strope = strlx.ToLower();
        //        if (strope != "add" && strope != "edit")
        //        {
        //            return Fail("strlx参数错误");
        //        }

        //        if (strope == "add")
        //        {
        //            if (string.IsNullOrEmpty(log.htid))
        //            {
        //                return Fail("日志关联的合同id不能为空");
        //            }

        //            log.tbr = GetUserId();
        //            log.tbrq = DateTime.Now;
        //            //重新赋值一个新id
        //            log.id = CommonHelper.GetUniqueId().ToString();
        //            log.createuser = GetUserId();

        //            log.status = BaseEditPower.GetSPEnumValue("待提交");

        //            //新增投资计划
        //            await ProJunGongRule.InsertHTLog(log, "add");


        //        }
        //        else if (strope == "edit")
        //        {
        //            if (string.IsNullOrEmpty(log.id))
        //            {
        //                return Fail("需要修改的日志id不能为空");
        //            }
        //            //if (string.IsNullOrEmpty(log.htid))
        //            //{
        //            //    return Fail("日志关联的合同id不能为空");
        //            //}


        //            //新增投资计划
        //            await ProJunGongRule.InsertHTLog(log, "edit");
        //        }


        //        return Success("成功");
        //    }
        //    catch (Exception ex)
        //    {
        //        return Fail("响应失败:" + ex.Message);
        //    }
        //}

        /// <summary>
        /// 删除合同日志
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteHTLogMulti(Root ids)//
        {
            try
            {
                foreach (BaseDeleteMulti idm in ids.ids)
                {
                    if (string.IsNullOrEmpty(idm.id))
                    {
                        return Fail("需要删除的变更编号不能为空");
                    }

                    //if (!await BaseEditPower.GetEditPower(idm.id, BaseEditPower.TableName.合同变更))
                    //{
                    //    //throw new Exception("请确认数据权限");
                    //    return Fail("响应失败:请确认数据权限");
                    //}
                }
            }
            catch (Exception ex)
            {
                return Fail("出错：" + ex.Message);
            }


            try
            {
                //新增投资计划
                if (await ProJunGongRule.DeleteHTLog(ids))
                {
                    return Success("成功");
                }
                else
                {
                    return Fail("影响行数为0");
                }

            }
            catch (Exception ex)
            {
                return Fail("响应失败:" + ex.Message);
            }
        }
        #endregion

        #region 用章

        #region 导出
        //"netapi/ProSeal/ExportList"
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> ExportSealList(dynamic expjson)
        {

            JObject job = (JObject)expjson;

            List<string> ids = new List<string>();
            List<ColumnModel> cols = new List<ColumnModel>();

            if (null != job["ids"])
                ids = job["ids"].ToObject<string[]>().ToList();

            if (null != job["cols"])
                cols = job["cols"].ToObject<ColumnModel[]>().ToList();

            //return File(await ProYongZhangRule.GetExportList(ids, cols), "application/ms-excel", "用章列表.xls");
            return File(await CProTZJHRule.GetExportList(ids, cols, BaseEditPower.TableName.用章, "用章列表"), "application/ms-excel", "用章列表.xls");
        }

        #endregion

        /// <summary>
        /// 项目用章列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        //[AllowAnonymous]
        public async Task<IActionResult> GetHTSealIndexList(string formCode, string yzlx, string yzmc, string yzwj, string yzbm, string yzr, string kssj, string jssj, string status, string current = "1", string size = "20", string sort = "desc", string column = "id")
        {
            try
            {
                dynamic dye = new ExpandoObject();
                dye.yzlx = yzlx;
                dye.yzmc = yzmc;
                dye.yzwj = yzwj;
                dye.yzbm = yzbm;
                dye.yzr = yzr;
                dye.kssj = kssj;
                dye.jssj = jssj;

                dye.status = status;
                dye.current = current;
                dye.size = size;
                dye.sort = sort;
                dye.column = column;

                string struid = GetUserId();

                //var SelectTable = await ProGuiDangRule.GetXMGDIndexList(dye,struid);
                (IEnumerable<dynamic>, int) SelectTable = await ProYongZhangRule.GetHTSealIndexList(dye, await GetDepId());

                List<string> list = new List<string>();
                foreach (dynamic item in SelectTable.Item1)
                {
                    string id = item.id;
                    list.Add(id);
                }

                List<JavaApi.SPSDataItem> spitems = await JavaApi.GetSPStatusJavaAPI(formCode, GetUserAccount(), list, await GetICApiInfo());
                foreach (dynamic item in SelectTable.Item1)
                {
                    string id = item.id;
                    var spstatus = spitems.Where(ii => ii.businessId == id).FirstOrDefault();

                    item.panguData = GetPanGudData(spstatus, item.spstatus);
                }

                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;


                return Success(pa);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 合同用章列表
        /// </summary>
        /// <param name="htid"></param>
        /// <param name="strlx"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHTSealList(string htid)
        {
            try
            {

                string struid = GetUserId();

                var SelectTable = await ProYongZhangRule.GetHTSealList(htid, struid);

                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }


        /// <summary>
        /// 单条合同用章
        /// </summary>
        /// <param name="sid"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHTSealByid(string sid)
        {
            try
            {
                var SelectTable = await ProYongZhangRule.GetHTSealByid(sid);

                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 修改合同用章
        /// </summary>
        /// <param name="seal"></param>
        /// <param name="strlx"></param>
        /// <returns></returns>
        [HttpPost]
        //[AllowAnonymous]
        public async Task<IActionResult> InsertHTSeal(dynamic sealjson)//, string strlx = "xxx"
        {
            string strope = "add";
            CProYongZhang seal = new CProYongZhang();

            //添加附件上传
            FileUploadent filecodes = new FileUploadent();
            try
            {
                JObject job = (JObject)sealjson;

                //获取方法
                strope = sealjson.ope ?? "";
                strope = strope.ToLower();

                //获取实体类 这样复杂类型不用定义实体类
                seal = job["seal"].ToObject<CProYongZhang>();


                //接收附件列表
                if (null != job["apiargs"])
                    filecodes = job["apiargs"].ToObject<FileUploadent>();


                if (strope != "add" && strope != "edit" && strope != "approved" && strope != "submit")
                {
                    return Fail("参数ope 不合法");
                }

            }
            catch (Exception ex)
            {
                return Fail("参数转换出错：" + ex.Message);
            }

            try
            {
                string strlsope = strope;
                if (strope == "submit")
                {
                    if (string.IsNullOrEmpty(seal.id))//完成新增
                    {
                        strope = "add";
                    }
                    else
                    {
                        CProYongZhang jhe = await TranstionRule.FindEntityByKey<CProYongZhang>(seal.id);
                        if (null == jhe)
                        {
                            strope = "add";
                        }
                        else
                        {
                            strope = "edit";
                        }
                    }
                    seal.status = BaseEditPower.GetSPEnumValue("待审核");
                }

                if (strope == "add")
                {
                    if (string.IsNullOrEmpty(seal.bmid))
                    {
                        return Fail("用章关联的部门id不能为空");
                    }


                    seal.yzbm = await JavaApi.BusinessBMJavaAPI(BaseEditPower.listTableName[BaseEditPower.TableName.用章.ToString()], Newtonsoft.Json.JsonConvert.SerializeObject(sealjson), await GetICApiInfo());
                    //await BusinessRule.Assets.CreateZCDM("XM", "YZ");

                    //seal.tbr = GetUserId();
                    //seal.tbrq = DateTime.Now;
                    //重新赋值一个新id
                    seal.id = CommonHelper.GetUniqueId().ToString();
                    seal.createuser = GetUserId();

                    if (strlsope != "submit")
                        seal.status = BaseEditPower.GetSPEnumValue("待提交");

                    //这里先绑定附件
                    await JavaApi.UploadFileJavaAPI(seal.id, filecodes, await GetICApiInfo());
                    bool bsp = true;
                    if (strlsope == "submit")
                    {
                        bsp = false;

                        var url = BaseEditPower.GetSPDetailUrlS(BaseEditPower.TableName.用章.ToString(), seal.id);


                        JavaApi.SPLEnt.Auditdescription _description = new JavaApi.SPLEnt.Auditdescription() { businessNo = seal.yzbm, amount = seal.wjsl?.ToString(), content = "[用章]" + seal.mc, deptName = GetUserDeptName() };


                        JavaApi.SPLEnt spl = new JavaApi.SPLEnt(BaseEditPower.TableName.用章.ToString(), seal.id, filecodes.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(sealjson), "http://ic-xmzc/netapi/ProTZJH/UpdateStatus", url.Item1, url.Item2, _description);
                        bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                        if (!bsp)
                        {
                            return Fail("提交失败，启动工作流异常");
                        }
                    }
                    //新增投资计划
                    await ProYongZhangRule.InsertHTSeal(seal, "add");


                }
                else if (strope == "edit")
                {
                    if (string.IsNullOrEmpty(seal.id))
                    {
                        return Fail("需要修改的用章id不能为空");
                    }
                    //if (string.IsNullOrEmpty(log.htid))
                    //{
                    //    return Fail("用章关联的部门id不能为空");
                    //}

                    //这里先绑定附件
                    await JavaApi.UploadFileJavaAPI(seal.id, filecodes, await GetICApiInfo());
                    bool bsp = true;
                    if (strlsope == "submit")
                    {
                        bsp = false;


                        CProYongZhang jhe = await TranstionRule.FindEntityByKey<CProYongZhang>(seal.id);
                        if (null == jhe)
                        {
                            return Fail("根据id未检索到用章信息");
                        }

                        var url = BaseEditPower.GetSPDetailUrlS(BaseEditPower.TableName.用章.ToString(), seal.id);

                        JavaApi.SPLEnt.Auditdescription _description = new JavaApi.SPLEnt.Auditdescription() { businessNo = jhe.yzbm, amount = seal.wjsl?.ToString(), content = "[用章]" + seal.mc, deptName = GetUserDeptName() };

                        JavaApi.SPLEnt spl = new JavaApi.SPLEnt(BaseEditPower.TableName.用章.ToString(), seal.id, filecodes.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(sealjson), "http://ic-xmzc/netapi/ProTZJH/UpdateStatus", url.Item1, url.Item2, _description);
                        bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                        if (!bsp)
                        {
                            return Fail("提交失败，启动工作流异常");
                        }
                    }
                    //新增投资计划
                    await ProYongZhangRule.InsertHTSeal(seal, "edit");
                }


                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail("响应失败:" + ex.Message);
            }
        }

        ///// <summary>
        ///// 修改合同用章
        ///// </summary>
        ///// <param name="seal"></param>
        ///// <param name="strlx"></param>
        ///// <returns></returns>
        //[HttpPost]
        //[AllowAnonymous]
        //public async Task<IActionResult> InsertHTSeal(CProYongZhang seal, string strlx = "xxx")//
        //{
        //    try
        //    {
        //        string strope = strlx.ToLower();
        //        if (strope != "add" && strope != "edit")
        //        {
        //            return Fail("strlx参数错误");
        //        }

        //        if (strope == "add")
        //        {
        //            if (string.IsNullOrEmpty(seal.bmid))
        //            {
        //                return Fail("用章关联的部门id不能为空");
        //            }

        //            //seal.tbr = GetUserId();
        //            //seal.tbrq = DateTime.Now;
        //            //重新赋值一个新id
        //            seal.id = CommonHelper.GetUniqueId().ToString();
        //            seal.createuser = GetUserId();

        //            seal.status = BaseEditPower.GetSPEnumValue("待提交");

        //            //新增投资计划
        //            await ProYongZhangRule.InsertHTSeal(seal, "add");


        //        }
        //        else if (strope == "edit")
        //        {
        //            if (string.IsNullOrEmpty(seal.id))
        //            {
        //                return Fail("需要修改的用章id不能为空");
        //            }
        //            //if (string.IsNullOrEmpty(log.htid))
        //            //{
        //            //    return Fail("用章关联的部门id不能为空");
        //            //}


        //            //新增投资计划
        //            await ProYongZhangRule.InsertHTSeal(seal, "edit");
        //        }


        //        return Success("成功");
        //    }
        //    catch (Exception ex)
        //    {
        //        return Fail("响应失败:" + ex.Message);
        //    }
        //}

        /// <summary>
        /// 删除合同用章
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteHTSealMulti(Root ids)//
        {
            try
            {
                foreach (BaseDeleteMulti idm in ids.ids)
                {
                    if (string.IsNullOrEmpty(idm.id))
                    {
                        return Fail("需要删除的变更编号不能为空");
                    }

                    //if (!await BaseEditPower.GetEditPower(idm.id, BaseEditPower.TableName.合同变更))
                    //{
                    //    //throw new Exception("请确认数据权限");
                    //    return Fail("响应失败:请确认数据权限");
                    //}
                }
            }
            catch (Exception ex)
            {
                return Fail("出错：" + ex.Message);
            }


            try
            {
                //新增投资计划
                if (await ProYongZhangRule.DeleteHTSeal(ids))
                {
                    return Success("成功");
                }
                else
                {
                    return Fail("影响行数为0");
                }

            }
            catch (Exception ex)
            {
                return Fail("响应失败:" + ex.Message);
            }
        }
        #endregion

        #region 归档

        #region 导出
        //XMGDIndexList
        //("netapi/ProXMGD/ExportList")
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> ExportXMGDList(dynamic expjson)
        {

            JObject job = (JObject)expjson;

            List<string> ids = new List<string>();
            List<ColumnModel> cols = new List<ColumnModel>();

            if (null != job["ids"])
                ids = job["ids"].ToObject<string[]>().ToList();

            if (null != job["cols"])
                cols = job["cols"].ToObject<ColumnModel[]>().ToList();

            //return File(await ProGuiDangRule.GetExportxmgdList(ids, cols), "application/ms-excel", "归档列表.xls");
            return File(await CProTZJHRule.GetExportList(ids, cols, BaseEditPower.TableName.归档, "归档列表"), "application/ms-excel", "归档列表.xls");
        }

        #endregion

        /// <summary>
        /// 归档筛选合同
        /// </summary>
        /// <param name="xmid"></param>
        /// <param name="current"></param>
        /// <param name="size"></param>
        /// <param name="sort"></param>
        /// <param name="column"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetGDHTIndexList(string xmid, string gdid, string current = "1", string size = "20", string sort = "desc", string column = "id")
        {
            try
            {
                dynamic dynamic = new ExpandoObject();
                //ProHeTongQuerry querry = new ProHeTongQuerry();
                //基础属性
                dynamic.size = size;
                dynamic.current = current;
                dynamic.sort = sort;
                dynamic.column = column;

                //项目id 归档id
                dynamic.xmid = xmid;
                dynamic.gdid = gdid;

                (IEnumerable<dynamic>, int) SelectTable = await ProGuiDangRule.GetXZHTIndexList(dynamic, await GetDepId());

                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                return Success(pa);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 项目归档列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        //[AllowAnonymous]
        public async Task<IActionResult> GetXMGDIndexList(string formCode, string xmmc, string xmfzr, string status, string gdstatusn,
            string xmnf, string jsdw, string xmflname,
            string current = "1", string size = "20", string sort = "desc", string column = "id")
        {
            try
            {
                dynamic dye = new ExpandoObject();
                dye.xmmc = xmmc;
                dye.xmfzr = xmfzr;
                dye.status = status;
                dye.gdstatus = gdstatusn;

                dye.xmnf = xmnf;
                dye.jsdw = jsdw;
                dye.xmflname = xmflname;


                dye.current = current;

                dye.size = size;
                dye.sort = sort;
                dye.column = column;

                string struid = GetUserId();

                //var SelectTable = await ProGuiDangRule.GetXMGDIndexList(dye,struid);
                (IEnumerable<dynamic>, int) SelectTable = await ProGuiDangRule.GetXMGDIndexList(dye, await GetDepId());

                List<string> list = new List<string>();
                foreach (dynamic item in SelectTable.Item1)
                {
                    string id = item.id;
                    list.Add(id);
                }

                List<JavaApi.SPSDataItem> spitems = await JavaApi.GetSPStatusJavaAPI(formCode, GetUserAccount(), list, await GetICApiInfo());
                foreach (dynamic item in SelectTable.Item1)
                {
                    string id = item.id;
                    var spstatus = spitems.Where(ii => ii.businessId == id).FirstOrDefault();

                    item.panguData = GetPanGudData(spstatus, item.spstatus);
                }

                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;


                return Success(pa);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }


        /// <summary>
        /// 单条项目归档根据xmid
        /// </summary>
        /// <param name="xmid"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetXMGDByxmid(string xmid)
        {
            try
            {
                var SelectTable = await ProGuiDangRule.GetXMGDByxmid(xmid);

                //项目费用
                SelectTable.xmfy = await ProGuiDangRule.GetXMGDMoneyByxmid(xmid);

                //业务id
                SelectTable.businessIds = await ProGuiDangRule.GetXMDXHTID(xmid);

                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 单条项目归档根据 归档id
        /// </summary>
        /// <param name="gdid"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetXMGDByid(string gdid)
        {
            try
            {
                var SelectTable = await ProGuiDangRule.GetXMGDByid(gdid);

                //项目费用
                SelectTable.xmfy = await ProGuiDangRule.GetXMGDMoneyByGDid(gdid);

                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 新增修改归档信息
        /// </summary>
        /// <param name="gd"></param>
        /// <param name="strlx"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertCProGD(dynamic gdjson)//, string strlx = "xxx"
        {
            string strope = "add";
            CProGD gd = new CProGD();

            //添加附件上传
            FileUploadent filecodes = new FileUploadent();
            try
            {
                JObject job = (JObject)gdjson;

                //获取方法
                strope = gdjson.ope ?? "";
                strope = strope.ToLower();

                //获取实体类 这样复杂类型不用定义实体类
                gd = job["gd"].ToObject<CProGD>();

                //if (null != job["tzxmids"])
                //    tzxmids = job["tzxmids"].ToObject<List<CProManageTZXM>>();

                //接收附件列表
                if (null != job["apiargs"])
                    filecodes = job["apiargs"].ToObject<FileUploadent>();


                if (strope != "add" && strope != "edit" && strope != "approved" && strope != "submit")
                {
                    return Fail("参数ope 不合法");
                }

            }
            catch (Exception ex)
            {
                return Fail("参数转换出错：" + ex.Message);
            }



            try
            {
                string strlsope = strope;
                if (strope == "submit")
                {
                    if (string.IsNullOrEmpty(gd.id))//完成新增
                    {
                        strope = "add";
                    }
                    else
                    {
                        CProGD jhe = await TranstionRule.FindEntityByKey<CProGD>(gd.id);
                        if (null == jhe)
                        {
                            strope = "add";
                        }
                        else
                        {
                            strope = "edit";
                        }
                    }
                    gd.status = BaseEditPower.GetSPEnumValue("待审核");
                }

                if (strope == "add")
                {
                    if (string.IsNullOrEmpty(gd.xmid))
                    {
                        return Fail("归档信息关联的xmid不能为空");
                    }

                    //CProGD jhe = await TranstionRule.FindEntity<CProGD>(new { xmid = gd.xmid });
                    //if (null == jhe)
                    //{

                    //}

                    //重新赋值一个新id
                    gd.id = CommonHelper.GetUniqueId().ToString();
                    gd.createuser = GetUserId();

                    if (strlsope != "submit")
                        gd.status = BaseEditPower.GetSPEnumValue("待提交");


                    //这里先绑定附件
                    //await JavaApi.UploadFileJavaAPI(gd.id, filecodes, await GetICApiInfo());
                    bool bsp = true;
                    if (strlsope == "submit")
                    {
                        bsp = false;
                        JavaApi.SPLEnt spl = new JavaApi.SPLEnt(BaseEditPower.TableName.归档.ToString(), gd.id, filecodes.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(gdjson), "http://ic-xmzc/netapi/ProTZJH/UpdateStatus");
                        bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                        if (!bsp)
                        {
                            return Fail("提交失败，启动工作流异常");
                        }
                    }

                    //新增投资计划
                    await ProGuiDangRule.Insertxmgd(gd, "add");
                }
                else if (strope == "edit")
                {
                    if (string.IsNullOrEmpty(gd.id))
                    {
                        return Fail("归档信息的id不能为空");
                    }


                    if (!await BaseEditPower.GetEditPower(gd.id, BaseEditPower.TableName.归档))
                    {
                        //throw new Exception("请确认数据权限");
                        return Fail("响应失败:请确认数据权限");
                    }

                    //这里先绑定附件
                    //await JavaApi.UploadFileJavaAPI(gd.id, filecodes, await GetICApiInfo());
                    bool bsp = true;
                    if (strlsope == "submit")
                    {
                        bsp = false;
                        JavaApi.SPLEnt spl = new JavaApi.SPLEnt(BaseEditPower.TableName.归档.ToString(), gd.id, filecodes.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(gdjson), "http://ic-xmzc/netapi/ProTZJH/UpdateStatus");
                        bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                        if (!bsp)
                        {
                            return Fail("提交失败，启动工作流异常");
                        }
                    }
                    //新增投资计划
                    await ProGuiDangRule.Insertxmgd(gd, "edit");
                }


                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail("响应失败:" + ex.Message);
            }
        }


        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertCProGDMulti(dynamic gdjson)//
        {

            string strope = "add";
            List<string> gdids = new List<string>();

            List<CProGD> gds = new List<CProGD>();

            //添加附件上传
            FileUploadent filecodes = new FileUploadent();
            try
            {
                JObject job = (JObject)gdjson;

                //获取方法
                strope = gdjson.ope ?? "";
                strope = strope.ToLower();

                //获取实体类 这样复杂类型不用定义实体类
                gdids = job["xmids"].ToObject<List<string>>();

                //if (null != job["tzxmids"])
                //    tzxmids = job["tzxmids"].ToObject<List<CProManageTZXM>>();

                //接收附件列表
                if (null != job["apiargs"])
                    filecodes = job["apiargs"].ToObject<FileUploadent>();


                if (strope != "add" && strope != "edit" && strope != "approved" && strope != "submit")
                {
                    return Fail("参数ope 不合法");
                }

            }
            catch (Exception ex)
            {
                return Fail("参数转换出错：" + ex.Message);
            }


            try
            {
                foreach (string idm in gdids)
                {
                    if (string.IsNullOrEmpty(idm))
                    {
                        return Fail("需要归档的项目id不能为空");
                    }

                    CProGD gd = await TranstionRule.FindEntity<CProGD>(new { xmid = idm });
                    if (gd != null)
                    {
                        return Fail("请选择可归档的数据");
                    }
                }

                foreach (string idm in gdids)
                {
                    CProGD gd = new CProGD();
                    gd.id = CommonHelper.GetUniqueId().ToString();
                    gd.xmid = idm;
                    gd.gdrq = DateTime.Now;
                    gd.createdate = DateTime.Now;
                    gd.createuser = GetUserName();

                    gds.Add(gd);
                }
            }
            catch (Exception ex)
            {
                return Fail("出错：" + ex.Message);
            }


            try
            {
                //新增投资计划
                if (await ProGuiDangRule.InsertxmgdMul(gds, "add"))
                {
                    return Success("成功");
                }
                else
                {
                    return Fail("影响行数为0");
                }

            }
            catch (Exception ex)
            {
                return Fail("响应失败:" + ex.Message);
            }
        }

        /// <summary>
        /// 删除项目归档信息
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteXMGDMulti(Root ids)//
        {
            try
            {
                foreach (BaseDeleteMulti idm in ids.ids)
                {
                    if (string.IsNullOrEmpty(idm.id))
                    {
                        return Fail("需要删除的归档编号不能为空");
                    }

                    if (!await BaseEditPower.GetEditPower(idm.id, BaseEditPower.TableName.归档))
                    {
                        //throw new Exception("请确认数据权限");
                        return Fail("响应失败:请确认数据权限");
                    }
                }
            }
            catch (Exception ex)
            {
                return Fail("出错：" + ex.Message);
            }


            try
            {
                //新增投资计划
                if (await ProGuiDangRule.DeleteXMGD(ids))
                {
                    return Success("成功");
                }
                else
                {
                    return Fail("影响行数为0");
                }

            }
            catch (Exception ex)
            {
                return Fail("响应失败:" + ex.Message);
            }
        }
        #endregion

        #region 决算
        #region 导出
        //XMGDIndexList
        //("netapi/ProXMJus/ExportList")
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> ExportXMJusList(dynamic expjson)
        {

            JObject job = (JObject)expjson;

            List<string> ids = new List<string>();
            List<ColumnModel> cols = new List<ColumnModel>();

            if (null != job["ids"])
                ids = job["ids"].ToObject<string[]>().ToList();

            if (null != job["cols"])
                cols = job["cols"].ToObject<ColumnModel[]>().ToList();

            return File(await CProTZJHRule.GetExportList(ids, cols, BaseEditPower.TableName.决算, "决算列表"), "application/ms-excel", "归档列表.xls");
        }

        #endregion
        /// <summary>
        /// 项目决算列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        //[AllowAnonymous]
        public async Task<IActionResult> GetXMJusIndexList(string formCode, string xmmc, string xmfzr, string status, string current = "1", string size = "20", string sort = "desc", string column = "id")
        {
            try
            {
                dynamic dye = new ExpandoObject();
                dye.xmmc = xmmc;
                dye.xmfzr = xmfzr;
                dye.status = status;
                dye.current = current;
                dye.size = size;
                dye.sort = sort;
                dye.column = column;

                string struid = GetUserId();

                //var SelectTable = await ProGuiDangRule.GetXMGDIndexList(dye,struid);
                (IEnumerable<dynamic>, int) SelectTable = await ProGuiDangRule.GetXMJusIndexList(dye, await GetDepId());

                List<string> list = new List<string>();
                foreach (dynamic item in SelectTable.Item1)
                {
                    string id = item.id;
                    list.Add(id);
                }

                List<JavaApi.SPSDataItem> spitems = await JavaApi.GetSPStatusJavaAPI(formCode, GetUserAccount(), list, await GetICApiInfo());
                foreach (dynamic item in SelectTable.Item1)
                {
                    string id = item.id;
                    var spstatus = spitems.Where(ii => ii.businessId == id).FirstOrDefault();

                    item.panguData = GetPanGudData(spstatus, item.spstatus);
                }

                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;


                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 单条项目决算信息根据项目id
        /// </summary>
        /// <param name="xmid"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetXMJueSByxmid(string xmid)
        {
            try
            {
                var SelectTable = await ProGuiDangRule.GetXMJueSByxmid(xmid);
                string strjusid = SelectTable.id;
                if (string.IsNullOrEmpty(strjusid))
                {
                    return Fail("该项目id下不存在决算信息");
                }
                SelectTable.jusmx = await ProGuiDangRule.GetXMJueSMXByjsid(SelectTable.id);

                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 单条项目决算信息根据决算id
        /// </summary>
        /// <param name="jid"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetXMJueSByid(string jid)
        {
            try
            {
                var SelectTable = await ProGuiDangRule.GetXMJueSByid(jid);
                string strjusid = SelectTable.id;
                if (string.IsNullOrEmpty(strjusid))
                {
                    return Fail("该项目id下不存在决算信息");
                }
                SelectTable.jusmx = await ProGuiDangRule.GetXMJueSMXByjsid(SelectTable.id);

                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        //[HttpPost]
        //[AllowAnonymous]
        //public async Task<IActionResult> InsertCProXMJuS1(CProJUS jusjson)//
        //{
        //    return Fail("参数转换出错：");
        //}
        //[HttpPost]
        //[AllowAnonymous]
        //public async Task<IActionResult> InsertCProXMJuS2(CProJuSMX jusjson)//
        //{
        //    return Fail("参数转换出错：");
        //}

        /// <summary>
        /// 新增修改决算信息
        /// </summary>
        /// <param name="jusjson"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertCProXMJuS(dynamic jusjson)//
        {
            string strope = "add";
            CProJUS jus = new CProJUS();
            List<CProJuSMX> jusmx = new List<CProJuSMX>();
            //添加附件上传
            FileUploadent filecodes = new FileUploadent();

            try
            {
                JObject job = (JObject)jusjson;

                //获取方法
                strope = jusjson.ope;
                strope = strope.ToLower();

                //获取实体类 这样复杂类型不用定义实体类
                jus = job["jusxx"].ToObject<CProJUS>();

                if (null != job["jusmx"])
                    jusmx = job["jusmx"].ToObject<CProJuSMX[]>().ToList();

                //接收附件列表
                if (null != job["apiargs"])
                    filecodes = job["apiargs"].ToObject<FileUploadent>();

                if (strope != "add" && strope != "edit" && strope != "submit")
                {
                    return Fail("参数ope 不合法");
                }

            }
            catch (Exception ex)
            {
                return Fail("参数转换出错：" + ex.Message);
            }

            try
            {
                string strlsope = strope;
                if (strope == "submit")
                {
                    if (string.IsNullOrEmpty(jus.id))//完成新增
                    {
                        strope = "add";
                    }
                    else
                    {
                        CProJUS jhe = await TranstionRule.FindEntityByKey<CProJUS>(jus.id);
                        if (null == jhe)
                        {
                            strope = "add";
                        }
                        else
                        {
                            strope = "edit";
                        }
                    }
                    jus.status = BaseEditPower.GetSPEnumValue("待审核");
                }

                if (strope == "add")
                {
                    if (string.IsNullOrEmpty(jus.xmid))
                    {
                        return Fail("决算信息关联的xmid不能为空");
                    }

                    //重新赋值一个新id
                    jus.id = CommonHelper.GetUniqueId().ToString();
                    jus.createuser = GetUserId();

                    if (strlsope != "submit")
                        jus.status = BaseEditPower.GetSPEnumValue("待提交");

                    //这里先绑定附件
                    await JavaApi.UploadFileJavaAPI(jus.id, filecodes, await GetICApiInfo());
                    bool bsp = true;
                    if (strlsope == "submit")
                    {
                        bsp = false;
                        JavaApi.SPLEnt spl = new JavaApi.SPLEnt(BaseEditPower.TableName.决算.ToString(), jus.id, filecodes.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(jusjson), "http://ic-xmzc/netapi/ProTZJH/UpdateStatus");
                        bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                        if (!bsp)
                        {
                            return Fail("提交失败，启动工作流异常");
                        }
                    }
                    //新增投资计划
                    await ProGuiDangRule.InsertXMJueS(jus, jusmx, "add");


                }
                else if (strope == "edit")
                {
                    if (string.IsNullOrEmpty(jus.id))
                    {
                        return Fail("决算信息的id不能为空");
                    }
                    //if (string.IsNullOrEmpty(log.htid))
                    //{
                    //    return Fail("用章关联的部门id不能为空");
                    //}

                    if (!await BaseEditPower.GetEditPower(jus.id, BaseEditPower.TableName.决算))
                    {
                        //throw new Exception("请确认数据权限");
                        return Fail("响应失败:请确认数据权限");
                    }

                    //这里先绑定附件
                    await JavaApi.UploadFileJavaAPI(jus.id, filecodes, await GetICApiInfo());
                    bool bsp = true;
                    if (strlsope == "submit")
                    {
                        bsp = false;
                        JavaApi.SPLEnt spl = new JavaApi.SPLEnt(BaseEditPower.TableName.决算.ToString(), jus.id, filecodes.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(jusjson), "http://ic-xmzc/netapi/ProTZJH/UpdateStatus");
                        bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                        if (!bsp)
                        {
                            return Fail("提交失败，启动工作流异常");
                        }
                    }
                    //新增投资计划
                    await ProGuiDangRule.InsertXMJueS(jus, jusmx, "edit");
                }


                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail("响应失败:" + ex.Message);
            }
        }

        /// <summary>
        /// 删除项目决算信息
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteXMJusMulti(Root ids)//
        {
            try
            {
                foreach (BaseDeleteMulti idm in ids.ids)
                {
                    if (string.IsNullOrEmpty(idm.id))
                    {
                        return Fail("需要删除的归档编号不能为空");
                    }

                    if (!await BaseEditPower.GetEditPower(idm.id, BaseEditPower.TableName.决算))
                    {
                        //throw new Exception("请确认数据权限");
                        return Fail("响应失败:请确认数据权限");
                    }
                }
            }
            catch (Exception ex)
            {
                return Fail("出错：" + ex.Message);
            }


            try
            {
                //新增投资计划
                if (await ProGuiDangRule.DeleteXMJusMulti(ids))
                {
                    return Success("成功");
                }
                else
                {
                    return Fail("影响行数为0");
                }

            }
            catch (Exception ex)
            {
                return Fail("响应失败:" + ex.Message);
            }
        }


        #endregion

        #region 移交
        /// <summary>
        /// 移交列表
        /// </summary>
        /// <param name="xmmc"></param>
        /// <param name="jf"></param>
        /// <param name="yf"></param>
        /// <param name="jgstatus"></param>
        /// <param name="current"></param>
        /// <param name="size"></param>
        /// <param name="sort"></param>
        /// <param name="column"></param>
        /// <returns></returns>
        [HttpGet]
        //[Authorize(Policy = "TestPolicy")]
        //[AllowAnonymous]
        //string formCode,
        public async Task<IActionResult> GetYiJiaoIndexList(string formCode, string xmmc, string dxmc, string xmfzr, string jf, string yf, string yjstatus, string status, string xmnf, string xmlx, string current = "1", string size = "20", string sort = "desc", string column = "id")
        {
            try
            {
                ProYiJiaoQuerry querry = new ProYiJiaoQuerry();
                //基础属性
                querry.size = CommonHelper.ParseInt(size);
                querry.current = CommonHelper.ParseInt(current);
                querry.sort = sort;
                querry.column = column;

                querry.Xmmc = xmmc;
                querry.dxmc = dxmc;
                querry.xmfzr = xmfzr;

                querry.Jf = jf;
                querry.Yf = yf;
                querry.YjStatus = yjstatus;

                querry.xmnf = xmnf;
                querry.xmlx = xmlx;

                querry.status = status;

                (IEnumerable<dynamic>, int) SelectTable = await ProJunGongRule.GetyijiaoList(querry, await GetDepId());//GetUserId()

                List<string> list = new List<string>();
                foreach (dynamic item in SelectTable.Item1)
                {
                    string id = item.id;
                    list.Add(id);
                }

                List<JavaApi.SPSDataItem> spitems = await JavaApi.GetSPStatusJavaAPI(formCode, GetUserAccount(), list, await GetICApiInfo());
                foreach (dynamic item in SelectTable.Item1)
                {
                    string id = item.id;
                    var spstatus = spitems.Where(ii => ii.businessId == id).FirstOrDefault();

                    item.panguData = GetPanGudData(spstatus, item.spstatus);
                }

                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                return Success(pa);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 合同移交
        /// </summary>
        /// <param name="htid"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetYJByhtid(string htid)
        {
            try
            {
                var SelectTable = await ProJunGongRule.GetYJByhtid(htid);

                var yjmxs = await ProJunGongRule.GetYJMXSByHTid(htid);
                if (null != SelectTable)
                    SelectTable.yjmxs = yjmxs;

                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 单条移交
        /// </summary>
        /// <param name="jgid"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetYJByid(string yjid)
        {
            try
            {
                var SelectTable = await ProJunGongRule.GetYJByid(yjid);

                var yjmxs = await ProJunGongRule.GetYJMXSByYjid(yjid);
                if (null != SelectTable)
                    SelectTable.yjmxs = yjmxs;
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }



        /// <summary>
        /// 插入修改
        /// </summary>
        /// <param name="yjjson"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertCProYJ(dynamic yjjson)//, string strlx
        {
            string strope = "add";
            CProYiJiao yj = new CProYiJiao();

            List<CProYiJiaoMX> list = new List<CProYiJiaoMX>();
            //添加附件上传
            FileUploadent filecodes = new FileUploadent();
            try
            {
                JObject job = (JObject)yjjson;

                //获取方法
                strope = yjjson.ope ?? "";
                strope = strope.ToLower();

                //获取实体类 这样复杂类型不用定义实体类
                yj = job["yj"].ToObject<CProYiJiao>();

                if (null != job["yjmxs"])
                    list = job["yjmxs"].ToObject<List<CProYiJiaoMX>>();

                //接收附件列表
                if (null != job["apiargs"])
                    filecodes = job["apiargs"].ToObject<FileUploadent>();


                if (strope != "add" && strope != "edit" && strope != "approved" && strope != "submit")
                {
                    return Fail("参数ope 不合法");
                }

            }
            catch (Exception ex)
            {
                return Fail("参数转换出错：" + ex.Message);
            }

            try
            {

                string strlsope = strope;
                if (strope == "submit")
                {
                    if (string.IsNullOrEmpty(yj.id))//完成新增
                    {
                        strope = "add";
                    }
                    else
                    {
                        CProYiJiao jhe = await TranstionRule.FindEntityByKey<CProYiJiao>(yj.id);
                        if (null == jhe)
                        {
                            strope = "add";
                        }
                        else
                        {
                            strope = "edit";
                        }
                    }
                    yj.status = BaseEditPower.GetSPEnumValue("待审核");
                }

                if (strope == "add")
                {
                    if (string.IsNullOrEmpty(yj.htid))
                    {
                        return Fail("竣工信息htid不能为空");
                    }
                    if (string.IsNullOrEmpty(yj.yjrq.ToString()))
                    {
                        return Fail("竣工信息竣工日期不能为空");
                    }

                    yj.id = CommonHelper.GetUniqueId().ToString();
                    yj.createuser = GetUserId();
                    yj.createdate = DateTime.Now;

                    if (strlsope != "submit")
                        yj.status = BaseEditPower.GetSPEnumValue("待提交");

                    CProYiJiao jge = await TranstionRule.FindEntity<CProYiJiao>(new { htid = yj.htid });
                    if (null != jge)
                    {
                        return Fail("该合同id已交信息已经存在不能新增操作");
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(yj.id.ToString()))
                    {
                        return Fail("已交信息id不能为空");
                    }

                    if (!await BaseEditPower.GetEditPower(yj.id, BaseEditPower.TableName.竣工))
                    {
                        return Fail("响应失败:请确认数据权限");
                    }
                }

                //这里先绑定附件
                await JavaApi.UploadFileJavaAPI(yj.id, filecodes, await GetICApiInfo());

                bool bsp = true;
                if (strlsope == "submit")
                {
                    bsp = false;
                    JavaApi.SPLEnt spl = new JavaApi.SPLEnt(BaseEditPower.TableName.移交.ToString(), yj.id, filecodes.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(yjjson), "http://ic-xmzc/netapi/ProTZJH/UpdateStatus");
                    bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                    if (!bsp)
                    {
                        return Fail("提交失败，启动工作流异常");
                    }
                }

                await BusinessRule.ProJunGongRule.InsertCProYJ(yj, list, strope, GetUserId());

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 根据根据htid删除多条数据
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteCProYJMulti(Root ids)
        {
            try
            {
                foreach (BaseDeleteMulti idm in ids.ids)
                {
                    if (!await BaseEditPower.GetEditPower(idm.id, BaseEditPower.TableName.移交))
                    {
                        throw new Exception("请确认数据权限");
                    }
                }

                await BusinessRule.ProJunGongRule.DeleteCProYJMulti(ids);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        #endregion

        #region 缺陷期

        [HttpGet]
        public async Task<IActionResult> GetHTQXQList(string formCode, string xmmc, string dxmc, string jf, string htid, string htbh, string status, string qxqzt, string current = "1", string size = "20", string sort = "desc", string column = "")
        {
            try
            {
                ProHTQXQQuerry querry = new ProHTQXQQuerry();
                //基础属性
                querry.size = CommonHelper.ParseInt(size);
                querry.current = CommonHelper.ParseInt(current);
                querry.sort = sort;
                querry.column = column;


                querry.Jf = jf;
                querry.Xmmc = xmmc;
                querry.Htid = htid;
                querry.Status = status;
                querry.qxqzt = qxqzt;

                //这里查询给默认状态
                if (!string.IsNullOrEmpty(querry.qxqzt))
                {
                    if (querry.qxqzt == "0")
                    {
                        //默认审核状态给已审核
                        //querry.Status = "checked";
                    }
                }

                querry.htbh = htbh;
                querry.dxmc = dxmc;

                (IEnumerable<dynamic>, int) SelectTable = await ProJunGongRule.GetHTqxqList(querry, await GetDepId());//GetUserId()

                List<string> list = new List<string>();
                foreach (dynamic item in SelectTable.Item1)
                {
                    string id = item.id;
                    list.Add(id);
                }

                List<JavaApi.SPSDataItem> spitems = await JavaApi.GetSPStatusJavaAPI(formCode, GetUserAccount(), list, await GetICApiInfo());
                foreach (dynamic item in SelectTable.Item1)
                {
                    string id = item.id;
                    var spstatus = spitems.Where(ii => ii.businessId == id).FirstOrDefault();

                    item.panguData = GetPanGudData(spstatus, item.spstatus);
                }

                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                return Success(pa);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 根据缺陷期id获取缺陷期信息
        /// </summary>
        /// <param name="keyValue"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHTQXQByqxqId(string qxqid)
        {
            try
            {
                var SelectTable = await ProJunGongRule.GetHTQXQByqxqId(qxqid);

                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 根据缺陷期id获取缺陷期信息
        /// </summary>
        /// <param name="keyValue"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHTQXQByhtId(string htid)
        {
            try
            {
                var SelectTable = await ProJunGongRule.GetHTQXQByhtId(htid);

                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }


        /// <summary>
        /// 根据根据htid删除多条结算数据
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteHTQXQMulti(Root ids)
        {
            try
            {
                foreach (BaseDeleteMulti idm in ids.ids)
                {
                    if (!await BaseEditPower.GetEditPower(idm.id, BaseEditPower.TableName.合同缺陷期))
                    {
                        throw new Exception("请确认数据权限");
                    }
                }

                await BusinessRule.ProJunGongRule.DeleteHTQXQMulti(ids);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 插入修改缺陷期数据
        /// </summary>
        /// <param name="js"></param>
        /// <returns></returns>
        [HttpPost]
        //[AllowAnonymous]
        public async Task<IActionResult> InsertHTQXQ(dynamic htjson)
        {
            string strope = "add";
            CProConQXQ htqxq = new CProConQXQ();

            //添加附件上传
            FileUploadent filecodes = new FileUploadent();
            try
            {
                JObject job = (JObject)htjson;

                //获取方法
                strope = htjson.ope ?? "";
                strope = strope.ToLower();

                //获取实体类 这样复杂类型不用定义实体类
                htqxq = job["qxq"].ToObject<CProConQXQ>();


                //接收附件列表
                if (null != job["apiargs"])
                    filecodes = job["apiargs"].ToObject<FileUploadent>();


                if (strope != "add" && strope != "edit" && strope != "submit")//&& strope != "edit" && strope != "approved"
                {
                    return Fail("参数ope 不合法");
                }

            }
            catch (Exception ex)
            {
                return Fail("参数转换出错：" + ex.Message);
            }

            try
            {

                string strlsope = strope;
                if (strope == "submit")
                {
                    if (string.IsNullOrEmpty(htqxq.id))//完成新增
                    {
                        strope = "add";
                    }
                    else
                    {
                        CProConQXQ jhe = await TranstionRule.FindEntityByKey<CProConQXQ>(htqxq.id);
                        if (null == jhe)
                        {
                            strope = "add";
                        }
                        else
                        {
                            strope = "edit";
                        }
                    }
                    htqxq.status = BaseEditPower.GetSPEnumValue("待审核");
                }


                if (strope == "add")
                {
                    if (string.IsNullOrEmpty(htqxq.htid))
                    {
                        return Fail("缺陷期信息htid不能为空");
                    }

                    htqxq.id = CommonHelper.GetUniqueId().ToString();
                    htqxq.bm = await JavaApi.BusinessBMJavaAPI(BaseEditPower.listTableName[BaseEditPower.TableName.合同缺陷期.ToString()], Newtonsoft.Json.JsonConvert.SerializeObject(htjson), await GetICApiInfo());

                    if (strlsope != "submit")
                        htqxq.status = BaseEditPower.GetSPEnumValue("待提交");

                    htqxq.createuser = GetUserId();
                    htqxq.createdate = DateTime.Now;

                    bool bsp = true;
                    if (strlsope == "submit")
                    {
                        bsp = false;


                        var url = BaseEditPower.GetSPDetailUrlS(BaseEditPower.TableName.合同缺陷期.ToString(), htqxq.id);

                        JavaApi.SPLEnt.Auditdescription _description = new JavaApi.SPLEnt.Auditdescription() { businessNo = htqxq.id, amount = "0", content = "[缺陷期]", deptName = GetUserDeptName() };

                        JavaApi.SPLEnt spl = new JavaApi.SPLEnt(BaseEditPower.TableName.合同缺陷期.ToString(), htqxq.id, filecodes.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(htjson), "http://ic-xmzc/netapi/ProTZJH/UpdateStatus", url.Item1, url.Item2, _description);
                        //bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                        string strInstanceId = await JavaApi.startInstanceJavaAPIStr(spl, await GetICApiInfo());
                        if (strInstanceId.StartsWith("err"))
                        {
                            return Fail("提交失败，启动工作流异常");
                        }
                        htqxq.spl = strInstanceId;
                    }

                    await ProJunGongRule.InsertHTQXQ(htqxq, strope);
                }
                else if (strope == "edit")
                {
                    if (string.IsNullOrEmpty(htqxq.id))
                    {
                        return Fail("缺陷期信息id不能为空");
                    }
                    if (string.IsNullOrEmpty(htqxq.htid))
                    {
                        return Fail("缺陷期信息htid不能为空");
                    }

                    if (!await BaseEditPower.GetEditPower(htqxq.id, BaseEditPower.TableName.合同缺陷期))
                    {
                        throw new Exception("请确认数据权限");
                    }


                    htqxq.createuser = GetUserId();
                    htqxq.createdate = DateTime.Now;

                    //这里先绑定附件
                    await JavaApi.UploadFileJavaAPI(htqxq.id, filecodes, await GetICApiInfo());

                    bool bsp = true;
                    if (strlsope == "submit")
                    {
                        bsp = false;

                        var url = BaseEditPower.GetSPDetailUrlS(BaseEditPower.TableName.合同缺陷期.ToString(), htqxq.id);

                        JavaApi.SPLEnt.Auditdescription _description = new JavaApi.SPLEnt.Auditdescription() { businessNo = htqxq.id, amount = "0", content = "[合同缺陷期]", deptName = GetUserDeptName() };

                        JavaApi.SPLEnt spl = new JavaApi.SPLEnt(BaseEditPower.TableName.合同缺陷期.ToString(), htqxq.id, filecodes.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(htjson), "http://ic-xmzc/netapi/ProTZJH/UpdateStatus", url.Item1, url.Item2, _description);

                        string strInstanceId = await JavaApi.startInstanceJavaAPIStr(spl, await GetICApiInfo());
                        if (strInstanceId.StartsWith("err"))
                        {
                            return Fail("提交失败，启动工作流异常");
                        }
                        htqxq.spl = strInstanceId;
                    }

                    await ProJunGongRule.InsertHTQXQ(htqxq, strope);
                }

                return Success("操作成功");

            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        #endregion

        #region 报表

        #region 图标1
        [HttpGet]
        public async Task<IActionResult> GetXMStatistic(string xmnd)
        {
            DataTable dts = await ProBBRule.GetEcharts(xmnd, await GetDepId());
            dts.Columns.Add("jhstb");
            dts.Columns.Add("jhjetb");

            //dts.jhstb = null;
            //dts.jhjetb = null;

            //decimal jhs1 = CommonHelper.ParseDecimal(dts.jhs1);
            //decimal jhs2 = CommonHelper.ParseDecimal(dts.jhs2);
            //if (jhs1 > 0)
            //{
            //    dts.jhstb = Math.Round((jhs2 - jhs1) / jhs1, 2);
            //}

            //decimal jhje1 = CommonHelper.ParseDecimal(dts.jhje1);
            //decimal jhje2 = CommonHelper.ParseDecimal(dts.jhje2);
            //if (jhje1 > 0)
            //{
            //    dts.jhjetb = Math.Round((jhje2 - jhje1) / jhje1, 2);
            //}

            for (int i = 0; i < dts.Rows.Count; i++)
            {
                decimal jhs1 = dts.Rows[i]["jhs1"].ToString().ToDecimal();
                decimal jhs2 = dts.Rows[i]["jhs2"].ToString().ToDecimal();
                if (jhs1 > 0)
                {
                    dts.Rows[i]["jhstb"] = Math.Round((jhs2 - jhs1) / jhs1, 2);
                }

                decimal jhje1 = dts.Rows[i]["jhje1"].ToString().ToDecimal();
                decimal jhje2 = dts.Rows[i]["jhje2"].ToString().ToDecimal();

                if (jhje1 > 0)
                {
                    dts.Rows[i]["jhjetb"] = Math.Round((jhje2 - jhje1) / jhje1, 2);
                }
            }
            return Success(dts);
        }

        [HttpGet]
        public async Task<IActionResult> GetXMecharts(string strlx, string xmnd)
        {
            try
            {
                if (string.IsNullOrEmpty(xmnd))
                {
                    xmnd = DateTime.Now.Year.ToString();
                }

                DataTable dts = await ProBBRule.GetEchartsXMHTZF(strlx, xmnd, await GetDepId());
                List<string> listname = new List<string>();
                List<string> listval = new List<string>();
                List<string> listval2 = new List<string>();
                for (int i = 0; i < dts.Rows.Count; i++)
                {
                    listname.Add(dts.Rows[i]["name"].ToString());
                    listval.Add(dts.Rows[i]["cc"].ToString());

                    if (strlx == "zf")
                    {
                        listval2.Add(dts.Rows[i]["zfje"].ToString());
                    }
                }
                dynamic d = new ExpandoObject();
                d.series = listname;
                d.data = listval;

                d.data1 = listval2;

                return Success(d);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        #endregion

        #region 图表2 项目预警
        [HttpGet]
        //[AllowAnonymous]
        public async Task<IActionResult> GetXMStatistic2(string xmnd)
        {
            var dts = await ProBBRule.GetEcharts2(xmnd, await GetDepId());

            return Success(dts);
        }
        #endregion

        #region 超付预警
        /// <summary>
        /// 合同列表
        /// </summary>
        /// <param name="xmid"></param>
        /// <param name="current"></param>
        /// <param name="size"></param>
        /// <param name="sort"></param>
        /// <param name="column"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetHTBBList(string xmmc, string htmc, string htbh, string htid, string kssj, string jssj, string current = "1", string size = "20", string sort = "desc", string column = "htbh")
        {
            try
            {
                dynamic dynamic = new ExpandoObject();
                //ProHeTongQuerry querry = new ProHeTongQuerry();
                //基础属性
                dynamic.size = CommonHelper.ParseInt(size);
                dynamic.current = CommonHelper.ParseInt(current);
                dynamic.sort = sort;
                dynamic.column = column;

                //项目名称 合同名称
                dynamic.xmmc = xmmc;
                dynamic.htmc = htmc;

                dynamic.kssj = kssj;
                dynamic.jssj = jssj;

                dynamic.htbh = htbh;
                dynamic.htid = htid;

                (IEnumerable<dynamic>, int) SelectTable = await ProBBRule.GetHTBBList(dynamic, await GetDepId());

                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                return Success(pa);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 合同列表超付
        /// </summary>
        /// <param name="xmid"></param>
        /// <param name="current"></param>
        /// <param name="size"></param>
        /// <param name="sort"></param>
        /// <param name="column"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetHTCFBBList(string xmmc, string htmc, string cfje = "0", string current = "1", string size = "20", string sort = "desc", string column = "htbh")
        {
            try
            {
                dynamic dynamic = new ExpandoObject();
                //ProHeTongQuerry querry = new ProHeTongQuerry();
                //基础属性
                dynamic.size = CommonHelper.ParseInt(size);
                dynamic.current = CommonHelper.ParseInt(current);
                dynamic.sort = sort;
                dynamic.column = column;

                //项目名称 合同名称
                dynamic.xmmc = xmmc;
                dynamic.htmc = htmc;

                dynamic.cfje = cfje;


                (IEnumerable<dynamic>, int) SelectTable = await ProBBRule.GetHTFKJHCFBBList(dynamic, await GetDepId(), "htcf");

                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                return Success(pa);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 合同列表超付
        /// </summary>
        /// <param name="xmid"></param>
        /// <param name="current"></param>
        /// <param name="size"></param>
        /// <param name="sort"></param>
        /// <param name="column"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetHTFKJHCFBBList(string xmmc, string htmc, string cfje, string current = "1", string size = "20", string sort = "desc", string column = "htbh")
        {
            try
            {
                dynamic dynamic = new ExpandoObject();
                //ProHeTongQuerry querry = new ProHeTongQuerry();
                //基础属性
                dynamic.size = CommonHelper.ParseInt(size);
                dynamic.current = CommonHelper.ParseInt(current);
                dynamic.sort = sort;
                dynamic.column = column;

                //项目名称 合同名称
                dynamic.xmmc = xmmc;
                dynamic.htmc = htmc;

                dynamic.cfje = cfje;

                (IEnumerable<dynamic>, int) SelectTable = await ProBBRule.GetHTFKJHCFBBList(dynamic, await GetDepId(), "fkjhcf");

                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                return Success(pa);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        #endregion

        #region 月付款计划

        [HttpGet]
        public async Task<IActionResult> GetHTYFKJHListBB(string xmmc, string htmc, string months, string cfje, string current = "1", string size = "20", string sort = "desc", string column = "id")
        {
            try
            {
                string strWhere = " 1=1 ";
                string strWhere1 = " 1=1 ";
                if (!string.IsNullOrEmpty(xmmc))
                {
                    strWhere += " and xmmc like '%" + xmmc + "%'";
                }

                if (!string.IsNullOrEmpty(htmc))
                {
                    strWhere += " and htmc like '%" + htmc + "%'";
                }

                if (!string.IsNullOrEmpty(months))
                {
                    strWhere += " and months like '%" + htmc + "%'";
                }

                if (!string.IsNullOrEmpty(cfje))
                {
                    strWhere1 += " and byzfje-jhje> " + CommonHelper.ParseDecimal(cfje);
                }

                strWhere += " and departid in " + await GetDepId();

                string strsql = @"
select * from (
select  id,htbh,htmc,dxmc,htje,bgje,sdje,yfje,months,jhje,(
select SUM(zfje) from CProFKMX where sqid in (
select id from CProFKSQ where jhid  = View_ProFKYJHLists.id
))byzfje from dbo.View_ProFKYJHLists
where " + strWhere + @"
)t where " + strWhere1 + @"
order by id desc";

                return Success(await TranstionRule.ProcessSql(strsql));
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        #endregion

        #region 竣工超期项目

        [HttpGet]
        public async Task<IActionResult> GetHTJGCQListBB(string xmmc, string htmc, string current = "1", string size = "20", string sort = "desc", string column = "id")
        {
            try
            {
                string strWhere = " 1=1 ";

                if (!string.IsNullOrEmpty(xmmc))
                {
                    strWhere += " and xmmc like '%" + xmmc + "%'";
                }

                if (!string.IsNullOrEmpty(htmc))
                {
                    strWhere += " and htmc like '%" + htmc + "%'";
                }

                strWhere += " and jgrq < jungrq ";

                strWhere += " and departid in " + await GetDepId();

                string strsql = @"
select id,htbh,htmc,dxmc,jf,yf,jgrq,jungrq from View_ProFKLists
where " + strWhere + " order by id desc";

                return Success(await TranstionRule.ProcessSql(strsql));
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        #endregion

        #region 招标
        [HttpGet]
        public async Task<IActionResult> GetHTZBList(string dwmc, string times, string hts = "0", string months = "1")
        {
            try
            {
                string strWhere = " 1=1 ";

                if (!string.IsNullOrEmpty(dwmc))
                {
                    strWhere += " and yf like '%" + dwmc + "%'";
                }

                if (string.IsNullOrEmpty(hts))
                {
                    hts = "0";
                }

                if (string.IsNullOrEmpty(months))
                {
                    months = "1";
                }

                strWhere += " and departid in " + await GetDepId();

                string strsql = @"select * from(
select row_number() over(partition by yf order by cc desc)rr, * from(
select tht.id, yf, htbh, (select COUNT(*) from CProContract where yf = tht.yf and htrq < DATEADD(MONTH, " + months + @", tht.htrq)
and htrq > tht.htrq
)cc
 from CProContract tht
left join CProManageLX on CProManageLX.id = tht.dxid
left join CProManage xm2 on CProManageLX.xmid = xm2.ID 

where " + strWhere + @"
and CONVERT(varchar(100), htrq, 23) <> '1900-01-01'
)t where cc > " + hts + @"
)tor where rr = '1' order by cc desc";


                if (string.IsNullOrEmpty(hts.Trim()))
                {
                    hts = "0";
                }

                if (string.IsNullOrEmpty(months.Trim()))
                {
                    hts = "1";
                }


                strsql = @"
select * from(
---排序
select row_number() over(partition by yf order by cc desc)rr, * from(
---总数
select tt.id, yf, htbh, htrq,
(select COUNT(*) from (
------------------2222

select distinct yf,id,htrq from (
select CProContractSF.id sfid,htid,dwmc yf,CProContract.id,dxid,htbh,htrq from CProContractSF
left join CProContract on CProContractSF.htid = CProContract.id
where lx = 'yf')t 
where ISNULL(id,'') <> ''
 
------------------2222
)tc 

where yf = tt.yf and htrq < DATEADD(MONTH, " + months + @", tt.htrq) and htrq > tt.htrq
)cc from (
----------------------
select * from (
select CProContractSF.id sfid,htid,dwmc yf,CProContract.id ,dxid,htbh,htrq from CProContractSF
left join CProContract on CProContractSF.htid = CProContract.id
where lx = 'yf')t 
where ISNULL(id,'') <> ''
----------------------
)tt 
left join CProManageLX on CProManageLX.id = tt.dxid
left join CProManage xm2 on CProManageLX.xmid = xm2.id 
where " + strWhere + @"
---总数
)ttt  where cc > " + hts + @"
---排序
)tttt
";
                _logger.Debug(strsql);

                return Success(await TranstionRule.ProcessSql(strsql));
            }
            catch (Exception ex)
            {

                return Fail(ex.Message);
            }
        }

        [HttpGet]
        public async Task<IActionResult> GetHTQDMXList(string tid, string dwmc, string months = "1")
        {
            try
            {
                string strWhere = " 1=1 ";


                strWhere += " and departid in " + await GetDepId();

                string strsql = @"select * from View_ProFKLists
where xmid not in (
select xmid from CProGD
) and htrq < DATEADD(MONTH," + months + @",(
(select htrq from CProContract where id = '" + tid + @"')
)) and yf = (select yf from CProContract where id = '" + tid + @"')";

                strsql = @" select htbh,htmc,dxmc,BuildUnit,xmmc,jf,yf,CONVERT(varchar(100), htrq, 23)htrq from (
select dwmc, CProContract.*from CProContractSF
left join CProContract on CProContractSF.htid = CProContract.id
 where lx = 'yf')t
 left join CProManageLX on t.dxid = CProManageLX.id
left join CProManage on CProManageLX.xmid = CProManage.id
where ISNULL(t.id,'') <> '' and htrq < DATEADD(MONTH," + months + @",(
(select htrq from CProContract where id = '" + tid + @"'))) and dwmc ='" + dwmc + "'";

                return Success(await TranstionRule.ProcessSql(strsql));
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        #endregion

        #region 非中标单位
        [HttpGet]
        public async Task<IActionResult> GetZBDWYFDiffList(string xmmc, string dxmc)
        {
            try
            {
                string strWhere = " 1=1 ";
                if (!string.IsNullOrEmpty(xmmc))
                {
                    strWhere += " and xmmc like '%" + xmmc + "%'";
                }
                if (!string.IsNullOrEmpty(xmmc))
                {
                    strWhere += " and dxmc like '%" + dxmc + "%'";
                }

                strWhere += " and departid in " + await GetDepId();

                string strsql = @"select CProManage.ID,CProManageLX.id dxid,xmmc,dxmc,htbh,CProManage.XYPosition,
CProContract.xmjl,jf,yf,htje,zbdw from CProContract
left join CProZB on CProContract.dxid = CProZB.dxid
left join CProManageLX on CProManageLX.id = CProContract.dxid
left join CProManage on CProManageLX.xmid = CProManage.ID
where " + strWhere + " and yf not like '%'+ ISNULL(zbdw,'') +'%' "; ;

                return Success(await TranstionRule.ProcessSql(strsql));
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        #endregion

        #region 项目列表
        [HttpGet]
        public async Task<IActionResult> GetXMIndexList(string xmmc, string xmfl, string buildUnit, string zjly, string year, string status, string current = "1", string size = "20", string sort = "desc", string column = "id")
        {
            try
            {
                CProManageQuerry querry = new CProManageQuerry();
                //基础属性
                querry.size = CommonHelper.ParseInt(size);
                querry.current = CommonHelper.ParseInt(current);
                querry.sort = sort;
                querry.column = column;


                querry.jsdw = buildUnit;
                querry.xmmc = xmmc;
                querry.xmfl = xmfl;
                querry.zjly = zjly;

                querry.year = year;
                querry.status = status;

                List<string> list = new List<string>();
                (IEnumerable<dynamic>, int) SelectTable = await CProManageRule.GetXMIndexList(querry, await GetDepId());

                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                return Success(pa);
            }
            catch (Exception ex)
            {
                return Fail("响应失败" + ex);
            }
        }
        #endregion
        #endregion


        #region 望亭报表2023

        //[FromBody]
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> getProjectProgress(ProReportQuerry querry)//string nd, string jsdwid
        {
 

            (IEnumerable<dynamic>, int) SelectTable = await ProJunGongRule.GetXMJDReportList(querry, await GetDepId());

            //(IEnumerable<dynamic>, int) SelectTable = dtsource.Item1;
            //节点配置
            List<BDICNODECONFIGURATION> listConfig = await ProJunGongRule.GetNodeConfig();


            List<BDICNODECONFIGURATION> listConfigproshow1 = listConfig.Where(it => it.proshow == true).ToList();
            List<BDICNODECONFIGURATION> listConfigtendersshow1 = listConfig.Where(it => it.tendersshow == true).ToList();




            List<dynamic> listdynamic = new List<dynamic>();
            foreach (dynamic item in SelectTable.Item1)
            {
                List<BDICNODECONFIGURATION> listConfigproshow = new List<BDICNODECONFIGURATION>();
                listConfigproshow1.ForEach(it => listConfigproshow.Add(CommonHelper.DeepCopy(it)));



                //if (jdlx == "xm")
                if (true)
                {

                    var dict = ((IDictionary<string, object>)item).ToDictionary(k => k.Key, v => v.Value?.ToString() ?? "");


                    //string strxmid = DynamicProperty(item, "xmid");
                    //string strxm = DynamicProperty(item, "xm");
                    //string strgsstatus = DynamicProperty(item, "gsstatus");

                    string strxmid = dict["xmid"];
                    string strxm = dict["xm"];
                    string strgsstatus = dict["gsstatus"];

                    List<jdnodename> listdxjd = await ProJunGongRule.GetXMJD_DX_ReportList(strxmid, "xm");

                    listdxjd = listdxjd ?? new List<jdnodename>();


                    for (int c = 0; c < listConfigproshow.Count; c++)
                    {
                        string jdmc = listConfigproshow[c].jdmc;

                        var dx_result = new List<jdnodename>();
                        if (jdmc == "项目立项")
                        {
                            listConfigproshow[c].values = strxm;
                        }
                        else if (jdmc == "项目概算")
                        {
                            listConfigproshow[c].values = strgsstatus;
                        }
                        else
                        {
                            //if (jdmc == "项目概算")
                            //{
                            //    dx_result = listdxjd.Where(it => it.gs != "unfilled").ToList();
                            //}
                            if (jdmc == "代理机构申请")
                            {
                                dx_result = listdxjd.Where(it => it.zbdljg != "unfilled").ToList();
                            }
                            if (jdmc == "预算编制")
                            {
                                dx_result = listdxjd.Where(it => it.ysbz != "unfilled").ToList();
                            }
                            if (jdmc == "预算复审")
                            {
                                dx_result = listdxjd.Where(it => it.ysfs != "unfilled").ToList();
                            }
                            if (jdmc == "招标申请")
                            {
                                dx_result = listdxjd.Where(it => it.zhaob != "unfilled").ToList();
                            }
                            if (jdmc == "中标录入")
                            {
                                dx_result = listdxjd.Where(it => it.zhongb != "unfilled").ToList();
                            }
                            if (jdmc == "合同录入")
                            {
                                dx_result = listdxjd.Where(it => it.qd != "unfilled").ToList();
                            }
                            if (jdmc == "竣工验收")
                            {
                                dx_result = listdxjd.Where(it => it.jg != "unfilled").ToList();
                            }
                            if (jdmc == "合同送审")
                            {
                                dx_result = listdxjd.Where(it => it.songs != "unfilled").ToList();
                            }
                            if (jdmc == "合同审计")
                            {
                                dx_result = listdxjd.Where(it => it.shend != "unfilled").ToList();
                            }
                            if (jdmc == "缺陷期解除")
                            {
                                dx_result = listdxjd.Where(it => it.htqxq != "unfilled").ToList();
                            }
                            if (jdmc == "项目归档")
                            {
                                dx_result = listdxjd.Where(it => it.gd != "unfilled").ToList();
                            }

                            if (dx_result.Any())
                            {
                                listConfigproshow[c].values = "checked";
                            }
                            else
                            {
                                listConfigproshow[c].values = "unfilled";
                            }
                        }
                    }

                    //项目的节点
                    item.process = listConfigproshow;

                    List<tenderinfo> listtenders = new List<tenderinfo>();
                    for (int t = 0; t < listdxjd.Count; t++)
                    {
                        List<BDICNODECONFIGURATION> listConfigtendersshow = new List<BDICNODECONFIGURATION>();
                        listConfigtendersshow1.ForEach(it => listConfigtendersshow.Add(CommonHelper.DeepCopy(it)));

                        jdnodename dxjd = listdxjd[t];

                        tenderinfo dytender = new tenderinfo();

                        dytender.id = dxjd.id;
                        dytender.xmid = dxjd.xmid;
                        dytender.xmmc = dxjd.xmmc;
                        dytender.xmbm = dxjd.xmbm;
                        dytender.buildunit = dxjd.buildunit;
                        dytender.dxmc = dxjd.dxmc;
                        dytender.lx = dxjd.lx;

                        dytender.htje = dxjd.htje;
                        dytender.zfbl = dxjd.zfbl;



                        for (int c = 0; c < listConfigtendersshow.Count; c++)
                        {
                            string jdmc = listConfigtendersshow[c].jdmc;

                            string strvalues = "";
                            var dx_result = new List<jdnodename>();
                            if (jdmc == "项目立项")
                            {
                                strvalues = "";
                            }
                            if (jdmc == "项目概算")
                            {
                                strvalues = "";
                            }
                            if (jdmc == "代理机构申请")
                            {
                                strvalues = dxjd.zbdljg;
                            }
                            if (jdmc == "预算编制")
                            {
                                strvalues = dxjd.ysbz;
                            }
                            if (jdmc == "预算复审")
                            {
                                strvalues = dxjd.ysfs;
                            }
                            if (jdmc == "招标申请")
                            {
                                strvalues = dxjd.zhaob;
                            }
                            if (jdmc == "中标录入")
                            {
                                strvalues = dxjd.zhongb;
                            }
                            if (jdmc == "合同录入")
                            {
                                strvalues = dxjd.qd;
                            }
                            if (jdmc == "竣工验收")
                            {
                                strvalues = dxjd.jg;
                            }
                            if (jdmc == "合同送审")
                            {
                                strvalues = dxjd.songs;
                            }
                            if (jdmc == "合同审计")
                            {
                                strvalues = dxjd.shend;
                            }
                            if (jdmc == "缺陷期解除")
                            {
                                strvalues = dxjd.htqxq;
                            }
                            if (jdmc == "项目归档")
                            {
                                strvalues = dxjd.gd;
                            }

                            listConfigtendersshow[c].values = strvalues;
                        }

                        dytender.process = listConfigtendersshow;

                        listtenders.Add(dytender);
                    }


                    item.tenderLists = listtenders;
                }


                listdynamic.Add(item);
            }


            Page pa = new Page();
            pa.records = listdynamic;
            pa.total = SelectTable.Item2;
            return Success(pa);
        }

        //[HttpPost]
        //[AllowAnonymous]
 
        [HttpGet("{type}/{id}")]
        //[AllowAnonymous]
        public async Task<IActionResult> getProjectProgresssingle(string type, string id)//string nd, string jsdwid
        {
            ProReportQuerry querry = new ProReportQuerry();
            //querry.condition = new Dictionary<string, conditionsigle>();

            querry.current = 1;
            querry.size = 100;

            if (type == "xm")
            {
                querry.xmid = id;
               // querry.condition.Add("xmid", new conditionsigle() { value = id, logic = Conditionenum.eq.ToString() });
            }
            else if (type == "bd")
            {
                querry.id = id;
                //querry.condition.Add("id", new conditionsigle() { value = id, logic = Conditionenum.eq.ToString() });
            }



            (IEnumerable<dynamic>, int) SelectTable = await ProJunGongRule.GetXMJDReportList(querry, await GetDepId());


            List<BDICNODECONFIGURATION> listConfig = await ProJunGongRule.GetNodeConfig();

            List<BDICNODECONFIGURATION> listConfigproshow = listConfig.Where(it => it.proshow == true).ToList();
            List<BDICNODECONFIGURATION> listConfigtendersshow = listConfig.Where(it => it.tendersshow == true).ToList();


            //List<dynamic> listdynamic = new List<dynamic>();
            dynamic itemsingle = new ExpandoObject();

            foreach (dynamic item in SelectTable.Item1)
            {
                //lx
                string jdlx = DynamicProperty(item, "lx");

                if (jdlx == "xm")
                {
                    //string lx = DynamicProperty(item, "lx");
                    //string strxmid = DynamicProperty(item, "xmid");
                    //string strxm = DynamicProperty(item, "xm");
                    //string strgsstatus = DynamicProperty(item, "gsstatus");

                    var dict = ((IDictionary<string, object>)item).ToDictionary(k => k.Key, v => v.Value?.ToString() ?? "");
                    string strxmid = dict["xmid"];
                    string strxm = dict["xm"];
                    string strgsstatus = dict["gsstatus"];

                    List<jdnodename> listdxjd = await ProJunGongRule.GetXMJD_DX_ReportList(strxmid, "xm");

                    listdxjd = listdxjd ?? new List<jdnodename>();


                    for (int c = 0; c < listConfigproshow.Count; c++)
                    {
                        string jdmc = listConfigproshow[c].jdmc;

                        var dx_result = new List<jdnodename>();
                        if (jdmc == "项目立项")
                        {
                            listConfigproshow[c].values = strxm;

                            listConfigproshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_prolists", strxmid, "id");
                        }
                        else if (jdmc == "项目概算")
                        {
                            listConfigproshow[c].values = strgsstatus;

                            listConfigproshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_progaispclists", strxmid, "xmid");
                        }
                        else
                        {

                            //if (jdmc == "项目概算")
                            //{
                            //    dx_result = listdxjd.Where(it => it.gs != "unfilled").ToList();

                            //    listConfigproshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_progaispclists", strxmid, "xmid");
                            //}
                            if (jdmc == "代理机构申请")
                            {
                                dx_result = listdxjd.Where(it => it.zbdljg != "unfilled").ToList();

                                listConfigproshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_prozbdljglists", strxmid, "xmid");
                            }
                            if (jdmc == "预算编制")
                            {
                                dx_result = listdxjd.Where(it => it.ysbz != "unfilled").ToList();

                                listConfigproshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_prozbbblists", strxmid, "xmid");
                            }
                            if (jdmc == "预算复审")
                            {
                                dx_result = listdxjd.Where(it => it.ysfs != "unfilled").ToList();

                                listConfigproshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_prozbbblistszz", strxmid, "xmid");
                            }
                            if (jdmc == "招标申请")
                            {
                                dx_result = listdxjd.Where(it => it.zhaob != "unfilled").ToList();

                                listConfigproshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_prozblists", strxmid, "xmid");
                            }
                            if (jdmc == "中标录入")
                            {
                                dx_result = listdxjd.Where(it => it.zhongb != "unfilled").ToList();

                                listConfigproshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_prozblists", strxmid, "xmid");
                            }
                            if (jdmc == "合同录入")
                            {
                                dx_result = listdxjd.Where(it => it.qd != "unfilled").ToList();

                                listConfigproshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_prohtlists", strxmid, "xmid");
                            }
                            if (jdmc == "竣工验收")
                            {
                                dx_result = listdxjd.Where(it => it.jg != "unfilled").ToList();

                                listConfigproshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_projungonglists", strxmid, "xmid");
                            }
                            if (jdmc == "合同送审")
                            {
                                dx_result = listdxjd.Where(it => it.songs != "unfilled").ToList();

                                listConfigproshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_projslists", strxmid, "xmid");
                            }
                            if (jdmc == "合同审计")
                            {
                                dx_result = listdxjd.Where(it => it.shend != "unfilled").ToList();

                                listConfigproshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_projslists", strxmid, "xmid");
                            }
                            if (jdmc == "缺陷期解除")
                            {
                                dx_result = listdxjd.Where(it => it.htqxq != "unfilled").ToList();

                                listConfigproshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_prohtqxqlists", strxmid, "xmid");
                            }
                            if (jdmc == "项目归档")
                            {
                                dx_result = listdxjd.Where(it => it.gd != "unfilled").ToList();

                                listConfigproshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_proguidang", strxmid, "xmid");
                            }

                            if (dx_result.Any())
                            {
                                listConfigproshow[c].values = "checked";
                            }
                            else
                            {
                                listConfigproshow[c].values = "unfilled";
                            }
                        }
                    }

                    item.process = listConfigproshow;

                }
                //标段
                else
                {

                    //string strdxid = DynamicProperty(item, "id");
                    //string strxmid = DynamicProperty(item, "xmid");

                    var dict = ((IDictionary<string, object>)item).ToDictionary(k => k.Key, v => v.Value?.ToString() ?? "");
                    string strxmid = dict["xmid"];
                    string strdxid = dict["id"];
 


                    List<jdnodename> listdxjd = await ProJunGongRule.GetXMJD_DX_ReportList(strdxid, "tender");

                    listdxjd = listdxjd ?? new List<jdnodename>();

                    jdnodename dxjd = listdxjd.FirstOrDefault() ?? new jdnodename();

                    for (int c = 0; c < listConfigtendersshow.Count; c++)
                    {
                        string jdmc = listConfigtendersshow[c].jdmc;

                        //string strvalues = "";
                        var dx_result = new List<jdnodename>();
                        if (jdmc == "项目立项")
                        {
                            listConfigtendersshow[c].values = "";

                            listConfigtendersshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_prolists", strxmid, "id");
                        }
                        if (jdmc == "项目概算")
                        {
                            listConfigtendersshow[c].values = "";

                            listConfigtendersshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_progaispclists", strxmid, "xmid");
                        }
                        if (jdmc == "代理机构申请")
                        {
                            listConfigtendersshow[c].values = dxjd.zbdljg;

                            listConfigtendersshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_prozbdljglists", strdxid, "dxid");
                        }
                        if (jdmc == "预算编制")
                        {
                            listConfigtendersshow[c].values = dxjd.ysbz;

                            listConfigtendersshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_prozbbblists", strdxid, "dxid");
                        }
                        if (jdmc == "预算复审")
                        {
                            listConfigtendersshow[c].values = dxjd.ysfs;

                            listConfigtendersshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_prozbbblistszz", strdxid, "dxid");
                        }
                        if (jdmc == "招标申请")
                        {
                            listConfigtendersshow[c].values = dxjd.zhaob;

                            listConfigtendersshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_prozblists", strdxid, "id");
                        }
                        if (jdmc == "中标录入")
                        {
                            listConfigtendersshow[c].values = dxjd.zhongb;

                            listConfigtendersshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_prozblists", strdxid, "dxid");
                        }
                        if (jdmc == "合同录入")
                        {
                            listConfigtendersshow[c].values = dxjd.qd;

                            listConfigtendersshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_prohtlists", strdxid, "dxid");
                        }
                        if (jdmc == "竣工验收")
                        {
                            listConfigtendersshow[c].values = dxjd.jg;

                            listConfigtendersshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_projungonglists", strdxid, "dxid");
                        }
                        if (jdmc == "合同送审")
                        {
                            listConfigtendersshow[c].values = dxjd.songs;

                            listConfigtendersshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_projslists", strdxid, "dxid");
                        }
                        if (jdmc == "合同审计")
                        {
                            listConfigtendersshow[c].values = dxjd.shend;

                            listConfigtendersshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_projslists", strdxid, "dxid");
                        }
                        if (jdmc == "缺陷期解除")
                        {
                            listConfigtendersshow[c].values = dxjd.htqxq;

                            listConfigtendersshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_prohtqxqlists", strdxid, "dxid");
                        }
                        if (jdmc == "项目归档")
                        {
                            listConfigtendersshow[c].values = dxjd.gd;

                            listConfigtendersshow[c].gridviewdata = await ProJunGongRule.GetXMJDReportDetailsList("view_proguidang", strxmid, "xmid");
                        }

                        //listConfigtendersshow[c].values = strvalues;
                    }

                    item.process = listConfigtendersshow;
                }



                //这里赋值
                itemsingle = item;
            }



            return Success(itemsingle);
        }
        #endregion
    }
}
